I learned from 1 to use Python in this 3 project I hope I can share what I learned this time with everyone, including the differences from Java !! In this ** Part 1, we will explain the differences & overview ** from Java, and in ** Part 2, we will explain the basic syntax (if statement & exception handling, etc.) **.
By the way, I only have the opportunity to use Java at work, and I got Java SE8 Gold in the summer of the third year, a year ago. (Reiwa started today !!)
・ What is Java? ・ What is Python? ・ Difference between Java and Python ・ Data type
Java is an object-oriented language that can be used on any computer as long as it runs the Java Virtual Machine (JVM). Compile language. The program can be used as it is even if the OS is replaced. Write once, run anywhere (write once, run anywhere). Java is also used when developing large-scale business systems such as those used in banks from small-scale applications used in mobile phones and smartphones.
① Business system ex. Shipping company delivery system, financial transaction system ② Android app ③ WEB application ex. Twitter ④ Game ex. Minecraft ⑤ Others ex. Software installed in home appliances, conventional mobile phones, Blu-ray players, etc.
Tips Google's three major languages ("Java", "C ++", "Python") Programming languages called C series such as C, C #, and C ++ have a language format similar to Java. In the first place, Java is designed as a language that removes the C ++ bug-prone specification and instead incorporates new features such as garbage collection.
An object-oriented language featuring simple code, abundant libraries, and versatility. Scripting language. It's not a specialized language for making something fixed, but a very versatile language that can make anything such as web, games, data analysis, GUI applications, etc. Recently, libraries suitable for fields such as big data processing, statistics, machine learning, and AI have been enriched and are being used more and more.
① WEB application ex. Dropbox, Instagram, Youtube, Evernote ② Desktop application (3) Business efficiency improvement It is possible to create tools that automate simple tasks such as VBA. ④ Embedded application ⑤ Machine learning / statistical analysis application ⑥ Game
Tips In the field of embedded applications, C language and C ++, which are closer to the form that can be understood by machines and are fast, are often used, but Python has a high affinity with C language and C ++, and Python calls processing such as C language. Can. Python source code is simpler to write than other programming languages. → Because the amount of source code that must be written is small and the writing method is limited. The grammar is simple and only the minimum necessary is prepared. (**** Offside rules *** etc.)
**** Off-side Rule *** (Off-side Rule) Specify the block by indentation instead of {}. Indentation is meaningful as a grammar, not for the legibility of the code.
In Java, the data type is first fixed in a fixed format ** (statically typed) **. → Translate (compile) into a computer-executable format before executing the program. On the other hand, in * Python, the data type is determined when the program is executed ** (dynamically typed) **. ~~ → You can execute the program without compiling. ~~ → When the script is started, the Python interpreter compiles the script into intermediate code (virtual machine language) and then executes it.
-Specify the block used in the for statement, etc. by indentation instead of {}. -It is not necessary to specify any keyword when declaring a variable. (Types such as Java String and Javascript var etc.) ・ There is no concept of constants. ・ "Else if" is "el if" -There is no switch ~ case statement. Instead, the "in" keyword can be used for similar implementation. * Details in Part 2 -The for statement is equivalent to the Java foreach statement. Often used in combination with the range function. Also, there is no do-while statement. * Details in Part 2 -Exception handling syntax is "try ~ except ~ else ~ finally" * Details are in Part 2. -There is a pass statement that explicitly indicates that nothing is done. * Details in Part 2
In Python, there are roughly 7 types ***.
① Integer type ~~ → Same as other languages such as Java. ~~ → Other languages such as Java are fixed-length integers. The integer type of Python is a variable-length integer, which is variable-length data like a character string, so there is no upper limit to the value. Larger values consume more memory.
② Floating point type → ** In the case of division (/), the result will be a floating point (Float) even for integer and integer operations. ** Truncate division (//) results in an integer.
③ Complex type → Complex numbers can be used. (Version 3.4 or later). If you add a subscript (j) to a number, you can treat it as a complex literal. Not Java.
④ Authenticity value → False is defined as "0" and True is defined as "1". Therefore, it is also possible to calculate these values directly with numerical values. By the way, ** It is not recognized as a boolean value unless the beginning is capitalized. ** **
There are four types of character strings that can be described. It is possible to define a character string (here document) that spans multiple lines by using triple quotes.
① Enclose the value in single quotes ② Enclose the value in double quotes ③ Enclose the value in triple single quotes ④ Enclose the value in triple double quotes
** Array in Java. ** The contents can be rewritten and can be handled sequentially. The types of values to include do not have to match. Data is declared in brackets [], separated by commas. A negative number can be specified for the argument and it can be displayed from the end.
lst=['test', 10, False]
print(lst[1]) #10
lst[1]=1000
print(lst[1]) #1000
lst[-1]=False
** Map in Java. ** The contents can be rewritten, and data is managed with a set of keys and values. Data is declared in curly braces {} with a set of keys and values separated by commas. The value types for the keys do not have to match in the dictionary.
directory={'key1': 'value1', 'key2': 'value2'}
print(directory['key1']) #value1
** Final declared array in Java. ** It has sequential like list type, but element cannot be changed. Data is declared in parentheses (), separated by commas. The types of values to include do not have to match. If the tuple contains only one value, a comma must be added at the end. ** Can also be used as a dictionary key. ** **
tuple1=('test', 10, True)
print(tuple[0]) #test
tuple2=('test', ) #One value to include in the tuple
** Set in Java. ** Not sequential and has no duplicate values. Therefore, each output result is not always as in the example. Data is generated by declaring the values in curly braces {} separated by commas, or by passing the values to a function called set. The "set" function receives a list type value or a character string as an argument, and when it receives a character string, manages it by separating it character by character.
sets1={'test',999,True}
print(sets1)# {True, ‘test’, 999}#
print(sets1[0])#This is NG because it has no order
sets3=set('hogehoge')
print(sets3) # {'e', 'h', 'o', 'g'} #Duplicates are eliminated
7.None Represents a null value.
As it is touted as simple code, there is no need to write Java class declarations, and the amount of source is small ♪ It seems easy to understand if you have Java experience! The basic syntax such as if statement and exception handling is explained in Part 2. It will be released soon ^ ^
・ [2017] Explaining a thorough comparison between Java and Python with zero technical terms https://www.sejuku.net/blog/36782
・ A Java programmer studied Python. (About type) https://qiita.com/riekure/items/57f306500636727bc125
-Compare differences between Python and Java classes, instances, and scopes http://kkv.hatenablog.com/entry/2015/04/12/164817
・ The 2018 Top Programming Languages --IEEE Spectrum Rankin https://spectrum.ieee.org/at-work/innovation/the-2018-top-programming-languages
・ Used by active engineers! 9 carefully selected Python machine learning libraries https://www.sejuku.net/blog/11551
・ The hottest Python in 2018! Thorough comparison of three web frameworks https://www.sejuku.net/blog/3713
・ AmadaShirou.Programing Keikensya No Tameno Python Saisoku Nyumon (Japanese Edition) Kindle Edition
Recommended Posts