01
变量和赋值
变量是一个实体的指代,通过“=”赋值。
通过id()方法可以查看变量的内存地址。
>>> id(1)
140724666242720
>>> a=1
>>> id(a)
140724666242720
a=1 即我们将a指向实体1,他们两个的内存地址是一样的。
变量支持重新赋值,被重新赋值后的值去哪了?
被系统回收了。
02python的六大基本类型
0 通过type()函数查看当前变量的数据类型>>> a=1
>>> type(a)
<class 'int'>
1/6
int 整数
如 1,2,3等。通过int()函数转换。
>>> type(1)
<class 'int'>
>>> b='1'
>>> type(b)
<class 'str'>
>>> b=int('1')
>>> type(b)
<class 'int'>
2/6
float 浮点数
如 1.1,1.2,1.3等。通过float()函数转换。
>>> type(1.1)
<class 'float'>
>>> b='1.1'
>>> type(b)
<class 'str'>
>>> b=float('1.1')
>>> type(b)
<class 'float'>
3/6
string 字符串 <