Two days of learning the basics of Python

Introduction to a series of articles on Python basics in two days

The two-day Python basics series of articles is the python part of the "learn by example" programming course. The original English Github repository is clicked here, and all the content has been posted to the short book (see chapters).
This series is only for learning and reference. My ability is limited. Many professional terms are in the process of learning. Please correct me if you make a mistake.

brief introduction:

From Wikipedia

Python is a widely used high-level programming language, a general-purpose programming language, created by Guido Van Rossum, the first edition was released in 1991. It can be regarded as an improved LISP (adding some advantages of other programming languages, such as object-oriented). As an interpreted language, Python's design philosophy emphasizes code readability and concise syntax (especially the use of space indentation to divide code blocks instead of braces or keywords). Compared to C++ or Java, Python allows developers to express ideas with less code. Regardless of whether it is a small or large program, the language tries to make the structure of the program clear.

Guido van Rossum (Dutch: Guido van Rossum, January 31, 1956 -), born in Haarlem, the Netherlands, is a computer programmer, the original designer and main architect of the Python programming language. In the Python community, Guido Van Rossum is considered a "benevolent dictator" (BDFL), which means that he still pays attention to the Python development process and makes decisions when necessary.

Installation

Hello World example

Let's start learning to use Python from a simple program:

#! /usr/bin/python3

print("Hello World")

The first line has two parts

The third line outputs the Hello World message, and the print function will add a newline after it by default.

Run Python program

You can use some text editors like gedit, vim or other editors to write script programs. After saving the file, add execute permission and run the program from the terminal.

$ chmod +x hello_world.py

$ ./hello_world.py
Hello World

Here is how to find the Python path and its version:

$ type python3
python3 is /usr/bin/python3

$ python3 --version
Python 3.4.3

If you have studied the Python 2 tutorial or have experience in Perl, it is easy to forget to add parentheses to the print function. This is a common mistake.

#! /usr/bin/python3

print "Have a nice day"
$ ./syntax_error.py
 File "./syntax_error.py", line 3
 print "Have a nice day"^
SyntaxError: Missing parentheses in call to 'print'

Single-line comments start at

#

In later chapters we will see multi-line comments

#! /usr/bin/python3

# Greeting message
print("Hello World")

Further reading

Python interpreter

$ python3
Python 3.4.3(default, Oct 142015,20:28:29)[GCC 4.8.4] on linux
Type "help","copyright","credits" or "license"for more information.>>>print("hi")
hi
>>> abc
Traceback(most recent call last):
 File "<stdin>", line 1,in<module>
NameError: name 'abc' is not defined
>>> num =5>>> num
5>>>3+47>>>12+ _
19>>> exit()

Further reading

Python Standard Library

The library contains built-in modules (written in C)—providing system feature interfaces such as file I/O and modules written in Python—providing standard solutions for many schedule programming problems.

Some of these modules encourage and enhance the compatibility of Python programs by abstracting platform-specific functions into platform-compatible APIs.

         Editor: Wu Pancheng

Recommended Posts

Two days of learning the basics of Python
Learn the basics of python interactive mode
Basics of Python syntax
How about learning python at the age of 27?
Consolidate the foundation of Python (4)
[898] python get the intersection of two lists | union | difference
Consolidate the foundation of Python(7)
Consolidate the foundation of Python(6)
Consolidate the foundation of Python(5)
General outline for the first day of learning python
Consolidate the foundation of Python (3)
The usage of wheel in python
Python handles the 4 wheels of Chinese
Python simulation of the landlord deal
What is the use of Python
The premise of Python string pooling
Secrets of the new features of Python 3.8
Learning path of python crawler development
The father of Python joins Microsoft
The operation of python access hdfs
The usage of tuples in python
End the method of running python
Python basics
Python basics
Python basics 3
Python basics 4
Python basics 5
Understanding the meaning of rb in python
Can Python implement the structure of the stack?
Python implements alternate execution of two threads
Logistic regression at the bottom of python
Solve the conflict of multiple versions of python
Python implements the sum of fractional sequences
What is the id function of python
Where is the pip path of python3
The essence of Python language: Itertools library
What are the advantages of python language
The specific method of python instantiation object
python3 realizes the function of mask drawing
What is the prospect of python development
What is the function body of python
The specific method of python import library
Solve the conflict of multiple versions of python
What is the function of adb in python
Detailed explanation of the principle of Python super() method
The difference between the syntax of java and python
python learning route
7 features of Python3.9
Python realizes the development of student management system
Python implements the shuffling of the cards in Doudizhu
The meaning and usage of lists in python
Solve the problem of python running startup error
Can the value of the python dictionary be modified?
Python 100 days plan
Python implements the source code of the snake game
Detailed explanation of the usage of Python decimal module
Recommendations of a few websites for learning Python
python list learning
2.1 The Python Interpreter (python interpreter)
The consequences of uninstalling python in ubuntu, very
Python object-oriented basics