In [1]: xfl_tuple = ('xuefeilong',21,175) 定义一个简单的元组
In [2]: type(xfl_tuple) 查看类型为元组类型
Out[2]: tuple
In [3]: xfl_tuple[0] 从零索引取值
Out[3]: 'xuefeilong'
In [4]: xfl_tuple[1]
Out[4]: 21
In [5]: xfl_tuple[2]
Out[5]: 175
In [6]: empty_tuple = () 定义一个空元组
In [7]: type(empty_tuple) 查看类型为元组类型
Out[7]: tuple
In [8]: empty_tuple. 查看元组的功能
empty_tuple.count empty_tuple.index
In [8]: single_tuple=()
In [9]: single_tuple=(1) 定义一个数据的元组必须加,号
In [10]: type(single_tuple) 查看类型为整形,这是初学者容易犯错
Out[10]: int
In [11]: single_tuple=(1,) 定义一个只有一个元素的元组,
必须加,号声明元组类型,加,表示其是一个元组,不然是整型,说明,是元组的标志
In [12]: type(single_tuple)
Out[12]: tuple
In [13]: num_list = [1,2,3,4] 定义一个列表
In [14]: type(num_list) 查看类型为列表
Out[14]: list
In [15]: num = tuple(num_list) 转换成元组类型
In [16]: type(num) 查看已经转换为元组类型
Out[16]: tuple
In [17]: num1 = list(num) 再次转换成列表
In [18]: type(num1) 查看已经转换为列表类型
Out[18]: list
python中单双引号用法的区别:
In [19]: print 'hello' 单双引号均可以正常输出
hello
In [20]: print "hello"
hello
In [21]: print 'he's boy' 单引号输出报错
File "<ipython-input-21-c3d94099ffdb>", line 1
print 'he's boy'
^
SyntaxError: invalid syntax
In [22]: print "he's boy" 用""进行输出
he's boy
In [23]: print 'he\'s boy' 加入\进行转义
he's boy