From scratch, computer beginners learn python
day01 language basics and variables
The first lesson on the first day starts with Hello world
2.1 Commonly used keywords
['False', 'None', 'True', 'and', 'as', 'assert', 'async', 'await',
'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except',
'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda',
'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
2.2 Common data types
a. Integer (int)-the type corresponding to all integers
b. Floating point (float)-the type of all decimals
c. String (str)-the type corresponding to all text
d. Boolean type (bool)-true and false corresponding types
3.1 Output function
a. print — Print the specified data on the console, or print multiple data at the same time
For example, print('hello') print(100,200,'hello')
b. Parameter end— By default, the value of end is a newline character, so after a print data is printed, it will automatically wrap.
print(100,200, end='.')
c. Parameter set— set is used to control the interval between data when a print prints out multiple data at the same time. The default is a space.
print(10, 20, 30, 40, sep='.') # 10.20.30.40
3.2 Input function
input (input prompt information)-Get the content entered from the console, and return it in the form of a string (when inputting, press Enter to end)
name = input('请输入姓名:')
print(name) # 输入的时候是什么数据,name中保存的就是什么
-
4.) Variable
4.1 What is a variable?
Variables are used to save data
4.2 Define variables
Syntax: variable = data
**a. Variable name: ** Named by the programmer; requirement: an identifier; not a keyword.
**b. "=": ** Auxiliary symbol, fixed writing.**c. Data: ** It can be any data type that needs to be saved, and it can be a variable that has been assigned; it can calculate expressions or function calls.
1. 使用变量 使用变量就是使用变量中保存的数据(数据能做的事情对应的变量都可以做) num = 10 print(num + 20) 2. 修改变量 age = 10 print(age) 3. 重新给变量赋值 age = 20 print(age) 4. 同一个变量可以保存不同类型的数据 age = 'adc' print(age) 5. 同时定义多个变量 1) 同时定义多个变量赋相同的值 变量名1 = 变量名2 = 变量名3 = 。。。 = 数据a = b = c = 100 print(a, b, c) 2) 同时定义多个变量赋不同的值 变量名1,变量名2,变量名3,。。。=数据1,数据2,数据3 x , y , z=1000, 2000, 3000 print( x, y, z )
-
5) Define variables and assign values to variables
When python defines a variable, it first opens up a suitable memory space according to the size of the data, then stores the data in the corresponding memory space, and finally binds the variable and the memory space and re-assigns the variable, it is to open up a new memory first For the saved new data, the new memory space size is the same as the new data size, and the variables are bound to the new memory space.
E.g:
x = 200 y = x print(id(x)) print(id(y)) # id(变量)-- 获取变量的地址
result
What variables really save in python is actually the address of the data in the memory.