Form
python variables generated without prior notice, the system according to the assignment operator or automatically infer variable type.
x = 123
type(x) # 数值型变量
y = '123'
type(y) # 数值型变量
Storage
python using " memory-based value management ", in essence, save variable values at the memory address, rather than the value itself.
# 多个变量指向同一个地址
x = 3
id(x)
y = 3
id(y)
modify
python with " assignment modifications" variables, that is, the specific =
right value assigned to variable on the left, is essentially a modified memory address variable points.
Note that the variable part of the definition of a variable name appears for the first time, but again belongs modify variables
x = 321
type(x) # 定义一个变量
x = 'abc'
type(x) # 赋值修改变量
name
The general principle is named " All names must be meaningful, at a glance ."
- Naming of
- Allow case letters, numbers, underline, and combinations thereof
- The first character can not be a number, and is case sensitive
- Underlined
_
achieve intervals, such asfirst_name
, can not be other symbols, and spaces - Caution lowercase
l
and uppercase lettersO
, as is easily mistaken for digital1
and0
- Reserved word or not, and the same functions built python
- Naming
- Small hump nomenclature: more words variables, the first letter lowercase first letter of each word in the back of the first word is capitalized. Such as
myFirstName
- Large hump nomenclature: also known as "Pascal's nomenclature," that the first letter of all words require capitalization. Such as
Person
,MyLastName
- Underline nomenclature: underlined
_
achieve interval, such asfirst_name
- Small hump nomenclature: more words variables, the first letter lowercase first letter of each word in the back of the first word is capitalized. Such as
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'
my_age = 1
id(my_age) # 定义一个变量my_age
my_age = 2
id(my_age) # 给变量my_age重新赋值后,my_age指向的内存地址发生改变
SeatNum1, SeatNum2 = 88, 99 # 可以同时给多个变量赋值