Named rules:
Project name Package name python file name
1. Cannot start with a number, cannot use Chinese
2. Cannot use keywords
3. English Letter Test_06_23
4. Alphanumeric underline (cannot start with a number)
5. See the name of knowing age
Variable:
x = 1 #定义一个变量x, and is assigned a value of 1
Print (x) #如果要引用某个变量 to ensure that the variable has been assigned a defined value
Common data types: shaping floating-point Boolean strings
age = #关键字 int
Score = 99.9 #浮点数 decimal key float
True #关键字 Boolean bool True False
False
String:
Content keyword in pairs of single or paired double quotes: str
Age = ' 20 '
Print (' X ')
Some special uses of strings:
A = ' Hello '
b = ' World '
c = 6
Concatenation of strings ' + ', "+" data types should be the same
String with other data types to do splicing coercion and then use ' + '
Forced conversion str (variable name/variable value)
Print (A+str (c))
', ', using a comma to output the result will be ordered an obvious space, string with other data types to be spliced
The slice value of the string (take left without right)
z = ' Hello '
The index of the string is starting from 0
Single String value: String variable name [index position]
Print (z[1]) E
Multiple string values: string variable name [where the character index begins: where the character index ends +1]
Print (Z[1:4]) ell
The character index ends where +1 has no bounds, so it can cross over
Print (Z[1:10]) Ello
Reverse order:
Print (z[-5:-3]) he
Last value: Print (Z[-1])
Formatted output:
Age = 18
Sex = ' female '
Print (' Lucy is %s years old, ' % of age ')
Print (' Lucy is%s years old, she's a%s ' % (age, Sex))
Print (' Lucy is {} years old '. Format (age))
Print (' Lucy is {0} years old, she's a {1} '. Format (age, Sex)
Placeholder:%s%f%d
Python Foundation _0623