Python: Day03, pythonday03
Configure Environment Variables
Right-click computer --- properties --- advanced system settings --- advanced --- environment variables --- system variables --- find Path, double-click Edit --- paste the program Path, remember that there is a semicolon before.
The Python program execution method is as follows:
1. Disadvantages: The program cannot be permanently saved. It is mainly used for simple syntax testing.
2. Component execution
Variable
Variables are used to store intermediate results during program operation and to facilitate future calls.
Variable naming rules
1. Be descriptive
2. The variable name can only be any combination of letters, numbers, or underscores. It cannot be a space or special character.
3. The variable name cannot contain Chinese characters.
4. It cannot start with a number.
5. Reserved characters (such as print, and, as, class, and del) cannot be used)
6. Generally, it does not start with an uppercase letter.
Constant: constant amount
All variables in py are variable, so all uppercase variable names are used to indicate that this variable is a constant.
Character encoding
ASCII
The first table supporting Chinese characters is GB2312.
1980 GB2312
1995 GBK1.0
2000 GB18030
Unicode universal code supports encoding in all countries and regions. It stores one character and occupies 2 bytes.
UTF-8 = extended set of unicode, variable length character delimiter set
Python2.x = default ASCII Encoding
Python3.x = unicode default encoding
Unicode is backward compatible with GB2312, GBK
There are two ways to change Python encoding:
1 ,#! -*-Coding: UTF-8 -*-
2. coding: UTF-8
Note
Single line comment :#
Multi-line comment: three single quotes or three double quotes, for example, ''' commented content ''' or "commented content """
1 death_age = 80 2 3 name = input ("your name:") 4 age = input ("your age:") # All data received by input is a string, even if you enter a number, it will still be treated as a string to process 5 6 # int integer = integer to convert the string to int, et int (converted data) 7 # str string = convert a number into a string using str, str (converted data) 8 9 print ("your name:", name) 10 print ("you can still live for", death_age-int (age), "years... ") 11 print (" you can still live for "+ str (death_age-int (age) +" years... ")
Note: (1) when printing a print, if multiple fields are separated by commas (,), a space is added to each field by default when the result is displayed; if the brackets contain several fields connected with the plus sign (+), no space is added between each field during printing. To add spaces between two fields, you must add a space in double quotation marks.
(2) If the parameters in the print brackets do not contain double quotation marks, they represent variables and text is added with double quotation marks.