1、Python变量类型:变量存储在内存中的值。这就意味着在创建变量时会在内存中开辟一个空间;
2、Python中的变量不需要声明变量类型,每个变量必须赋值后才被创建,赋值方式:变量名 = 变量值;
unm = 1;
strs = "121212";
print unm;
print strs;
D:\pycharm\untitled\venv\Scripts\python.exe D:/pycharm/untitled/hello.py
1
121212
Process finished with exit code 0
3、多个变量赋值:
a = b = c = 1;
print a,b,c;
输出:
D:\pycharm\untitled\venv\Scripts\python.exe D:/pycharm/untitled/hello.py
1 1 1
Process finished with exit code 0
a ,b ,c = 1 , 2 , "1212";
print a,b,c;
输出:
D:\pycharm\untitled\venv\Scripts\python.exe D:/pycharm/untitled/hello.py
1 2 1212
Process finished with exit code 0
4、标准数据类型:Numbers【数字】、String【字符串】、List【数组】、Tuple【元组】、Dictionary【字典】;
5、Python 数字 Numbers:
数字类型在赋值之后就不能改变了,改变就意味着从新分配了一个新的对象,可以 通过del删除引用的对象:
Python支持四种类型的数字:int、long【长整型】、float【浮点】、complex【复数】;
6、Python 字符串 String:
String 是由数字、下划线、字母组成的一串字符;
Python字符列表有两种取值方式:从左至右【0开始】、从右至左【-1开始】
获取字符中中的一段字符:[头下标:尾下标] 【其中下标从0开始,可正数可负数,尾下标不填则取值到最后】
字符列表截取可以给三个参数:[头下标:尾下标:步长]
例:
strs = "123456789";
print strs[1:5:2]
输出
24
7、Python 列表 【List】:
List 有序的对象集合;
列表可以完成大多数集合类数据结构的实现,支持数字、字符甚至包括列表即嵌套;
列表的标识 [ ] 内部用逗号隔开;
列表的截取和字符的截取一样【下标可为空,表示取到头或尾】
+号是列表的连接符、*号 表示重复操作;
例:
lists = ['1','2','6'];
lists2 = ['3','7','8'];
print lists+lists2;
print lists2*3;
输出:
['1', '2', '6', '3', '7', '8']
['3', '7', '8', '3', '7', '8', '3', '7', '8']
8、Python 元组 【Tuple】:
Tuple 元组的标识:()内部用逗号隔开,元组不能第二次赋值,相当于只读的List;
9、Python 字典 【Dictionary】:
Dictionary 无序的对象集合;
Dictionary 和 List 的区别:
List:有序、利用偏移量来存取;
Dictionary:无序、利用键值对来存取;
Dictionary 标识 { } 是由【索引】 key 和【值】 value 组成;
例:
dictionary1 = {"a":1,"b":2}
print dictionary1["a"];
dictionary1["c"] = 3;
print dictionary1.keys();
print dictionary1.values();
输出:
1
['a', 'c', 'b']
[1, 3, 2]
10、Python数据类型的转换:
数据类型的转换只需要将数据类型名作为函数名即可;
注意:元组不能转换尾字典;