01Python基础_02变量
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了01Python基础_02变量相关的知识,希望对你有一定的参考价值。
1. 数字Numbers:
int long float complex
10 51924361L 0.0 3.14j
100 -0x19323L 15.20 45.j
-786 0122L -21.9 9.322e-36j
080 0xDEFABCECBDAECBFBAEl 32.3e+18 .876j
-0490 535633629843L -90. -.6545+0J
-0x260 -052318172735L -32.54e100 3e+26J
0x69 -4721885298529L 70.2E-12 4.53e-7j
2. 字符串String: ‘ ’
字符串是:有序、不可变的
1 s = ‘ilovepython‘ 2 print(s[1:5]) #out: love
3. 列表List: [ ]
列表是:有序、可变的
1 list = [ ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 ] 2 tinylist = [123, ‘john‘] 3 4 print list # [‘runoob‘, 786, 2.23, ‘john‘, 70.2] 5 print list[0] # runoob 6 print list[1:3] # [786, 2.23] 7 print list[2:] # [2.23, ‘john‘, 70.2] 8 print tinylist * 2 # [123, ‘john‘, 123, ‘john‘] 9 print list + tinylist # [‘runoob‘, 786, 2.23, ‘john‘, 70.2, 123, ‘john‘]
4. 元组Tuple: ( )
元组是:有序、不可变的
1 tuple = ( ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 ) 2 list = [ ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 ] 3 tuple[2] = 1000 # 元组中是非法应用 4 list[2] = 1000 # 列表中是合法应用
5. 字典Dict: { }
字典是:无序、key值不可变,value可变的
1 dict = {} 2 dict[‘one‘] = "This is one" 3 dict[2] = "This is two" 4 tinydict = {‘name‘: ‘john‘,‘code‘:6734, ‘dept‘: ‘sales‘} 5 6 print dict[‘one‘] # This is one 7 print dict[2] # This is two 8 print tinydict # {‘dept‘: ‘sales‘, ‘code‘: 6734, ‘name‘: ‘john‘} 9 print tinydict.keys() # [‘dept‘, ‘code‘, ‘name‘] 10 print tinydict.values() # [‘sales‘, 6734, ‘john‘]
以上是关于01Python基础_02变量的主要内容,如果未能解决你的问题,请参考以下文章