[For beginners] Basics of Python explained by Java Gold Part 1

Overview

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 !!) _106250427_japanera-2.jpg

agenda

・ What is Java? ・ What is Python? ・ Difference between Java and Python ・ Data type

  1. Numeric type
  2. String type
  3. List type
  4. Dictionary type
  5. Tuple type
  6. Collective type (set type)   7. None ·Finally ・ References

What is Java

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.

What can be developed with java

① 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.

What is Python

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.

What you can develop with Python

① 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.

Difference between Java and Python

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.

Also in Python

-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

Data type

In Python, there are roughly 7 types ***.

  1. Numeric type
  2. String type
  3. List type
  4. Dictionary type
  5. Tuple type
  6. Collective type (set type)
  7. None

1. Numeric type

① 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. ** **

2. String type

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

3. List type

** 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

4. Dictionary type

** 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

5. Tuple type

** 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

6. Collective type

** 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.

Finally

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 ^ ^

References

・ [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

[For beginners] Basics of Python explained by Java Gold Part 2
[For beginners] Basics of Python explained by Java Gold Part 1
Basics of Python × GIS (Part 1)
[Linux] Basics of authority setting by chmod for beginners
Basics of Python x GIS (Part 3)
■ Kaggle Practice for Beginners --Introduction of Python --by Google Colaboratory
Basics of Python x GIS (Part 2)
Learn the basics of Python ① Beginners
[Python] Minutes of study meeting for beginners (7/15)
[Learning memo] Basics of class by python
Pandas of the beginner, by the beginner, for the beginner [Python]
A textbook for beginners made by Python beginners
Basics of Python ①
Basics of python ①
Python learning memo for machine learning by Chainer Chapter 13 Basics of neural networks
For new students (Recommended efforts for Python beginners Part 1)
Easy understanding of Python for & arrays (for super beginners)
Basics of pandas for beginners ② Understanding data overview
Basic story of inheritance in Python (for beginners)
Python basics ② for statement
Basics of Python scraping basics
python textbook for beginners
Basics of python: Output
OpenCV for Python beginners
Learning flow for Python beginners
Sample source of Observer pattern realized by Java, PHP, Python
[For beginners] Summary of standard input in Python (with explanation)
python: Basics of using scikit-learn ①
Python3 environment construction (for beginners)
Overview of Docker (for beginners)
Python #function 2 for super beginners
Basic Python grammar for beginners
Pandas basics for beginners ④ Handling of date and time items
100 Pandas knocks for Python beginners
[Python] The biggest weakness / disadvantage of Google Colaboratory [For beginners]
Python for super beginners Python #functions 1
Python #list for super beginners
~ Tips for beginners to Python ③ ~
[Python machine learning] Recommendation of using Spyder for beginners (as of August 2020)
Wrap (part of) the AtCoder Library in Cython for use in Python
A brief summary of Graphviz in python (explained only for mac)
Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)
Python techniques for those who want to get rid of beginners
Implementation example of hostile generation network (GAN) by keras [For beginners]
Automatic creation of 2021 monthly calendar (refill for personal organizer) by Python
Pandas basics for beginners ① Reading & processing
Pandas basics for beginners ⑧ Digit processing
Python Exercise for Beginners # 2 [for Statement / While Statement]
Expansion by argument of python dictionary
Python for super beginners Python # dictionary type 1 for super beginners
Machine learning summary by Python beginners
Seaborn basics for beginners ② Histogram (distplot)
Getting Started with Python Basics of Python
Python #index for super beginners, slices
Typing automation notes by Python beginners
<For beginners> python library <For machine learning>
Review of the basics of Python (FizzBuzz)
Python #len function for super beginners
Beginners use Python for web scraping (1)
Behavior of python3 by Sakura's server
Run unittests in Python (for beginners)