1. Naming rules 1> do not start with a number, without the Chinese name 2> without the keyword Int/pass/def/return such as 3> use letters, numbers, underscores named like class_06224> Best can see the name of the idea Str_to_list2. Variables
x = 1 y = ' hello ' #定义一个变量, and is assigned to a variable, which is a tool for storing data for later use
#在引用一个变量时, make sure that this function is defined
3. Common data types
Integer floating-point Boolean string
Aga = #整型
Score = 89.89 #浮点型
True/false #关键字Boolean BOOL Only these two
name = ' Hello ' pwd = "Fsdfs" #凡是用成对的单引号, enclosed in double quotes is the string "/" "
1> Special usage of strings
Concatenation of Strings +/,/cast
Print (a+b) #要求拼接的两边要类型一致, print () output function
Print (A, b) #对数据类型没有要求
STR (variable name/variable value) forces the contents of parentheses to be converted to STR, or to other, such as List (str), to convert STR to
2> String Slice values
z = ' Hello '
The index number of the # string is starting from 0
How do I value a string? -----> string variable name [index position] z[0] #输出 h
3# take a certain value? -----> string variable name [index start position: Position at end of index +1] in Z[1:3] #输出 el
-------> Slicing left and Right (view index, easy to understand)
' Hello ' Print (Z[2:4]) #结果为: LL Print (Z[-3:-1]) #结果为: LL
Print (z[-2:]) #取从-2 position to the last
3> formatted output
Age = 20
Sex = ' Girlprint ("The Dream Spring and autumn this year%s years old"%age) #格式化输出
Print ("Flower this year%s years, is a% is"% (age,sex)
Print ("Flower {0} years old this year, is a {2}". Format (Age,sex)
Placeholder%s%d%f
4. Notes
1> single-line comment #
2> Multi-line comment #选中多行, CTRL +/
3> three-quote Comment
"' Hello python book '
Error message:
Nameerror:name ' x ' is not defined variable X not defined
Python Learning _1_ Basics