1.python version selection, Python 2.x Or python 3.x?
Python 2.x version will only be updated to 2.7 will not have 2.8 version, the future mainstream is the Python 3.x version, so learn the normal situation Select 3.x version can!
2.python Installation:
Python official website: https://www.python.org/downloads/
The installation steps are as follows:
To test whether the installation was successful:
Windows User: WIN + R ==> input cmd Open command Line window ==> python--version ==> Enter
Linux Follow-up supplement ...
If the version number is displayed correctly, the installation is successful
If you are prompted without a python command, and Python is installed properly, you need to check to see if the environment variable is added.
Refer to Dangeal Big article (Win7 operation): https://www.cnblogs.com/dangeal/p/5455005.html
3. The first helloworld! written using Python
3.1 Printing directly on the command line
Open a command-line window: Python---enter
Input: Print ("Hello world!") Enter to successfully print out Hello world!
Enter: Exit () to exit the Python command
Format: Print ("What to print") can also use single quotation marks: print (' What to print ')
As follows:
3.2 Execute python file with python command output Hello world!
E Packing directory, create a new txt text file, name hello while changing the file suffix named. py
Using the text Editing tool (for example: notepad++) to open hello.py, enter: Print ("Hello world!")
CMD open a command-line window, enter Python E:\Hello.py--and enter the tip: Enter E:\ He can press the TAB key to complete the file name automatically (folder also applies)
Variables and constants in 4.python
4.1 Variable Constants Basic Introduction
Variables: can store calculated results or information to facilitate subsequent program calls and modifications
Constant: Fixed amount, in Python, the name of the constant is all uppercase
For example: name = "Tom"
is to assign the string tom to the variable name, where the variable is named, and the value of the variable is Tom
The value of name is not fixed and can be changed by continuing to assign a value
Name = "Rye", at which point the value of the variable name is no longer tom but a new value, Rye
4.2 Naming conventions for variables
1. Can consist of alphanumeric underscores such as: STUDETN1, Student2, Student_name
2. Cannot start with a number, cannot contain special characters (include, ~,!, @,#,$,%,^,&, etc.) or spaces, error example: 1name, name$, student name
3. Cannot be named with a reserved word, for example:
[' False ', ' None ', ' True ', ' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' fi Nally ', ' for ', ' from ', ' global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' nonlocal ', ' not ', ' or ', ' Pass ', ' raise ', ' return ', ' Try ', ' while ', ' with ', ' yield ']
4. Specification: cannot be named in Chinese, although Python can support
5. Multiple list of variable names, should use the hump named: Studentname, or use _ to connect multiple orders: Student_name
6. The name of the variable should be known, for example: Name = "Tom" age = 18, it is easy to know that the variable is the name and the ages, the error example: a = "Tom", variable A does not accurately express what he means
7. Variable names are case-sensitive, for example name = Tom, name = Rye, you can tell by executing the program that two are not the same variable
Annotations in 5.python
Single-line Comment: # print ("Hello world!") If you use # then the content after #, the program will not execute
Multiline comment: "", or "" "" "
"' The content to be annotated '
Logical judgment statements in 6.python
If condition:
Do someting1
else:
Do Something2
The statement means that if the condition condition after the IF is true, do someting1 is executed, otherwise do someting2
Attention:
1.if condition and else need to add:
2. To execute the condition body, such as do sometion1, you need to indent or space, if there are more than one line, it is necessary to ensure that the indentation format of each row is the same
3. Although the indentation is visually equal to the size of four spaces, the actual two are not the same
Multi-conditional Judgment statement format, according to business needs, you can combine multiple conditions at the same time
If Condition1:
Do someting1
Elif Condition2:
Do Someting2
Elif ...:
.....
else:
Do otherthing ...
Features: Judging from condition1 start to else end, if a condition is met in this procedure, the program executes the logic under that condition and the other conditions will no longer execute
Writing in a Python file
MyAge =myfatherage = if myAge = = myfatherage: print(" ")elif myAge < myfatherage: print(" ")else: print(" ")
Python Learning _01