首页 > 编程语言 > 详细

01Python基础_02变量

时间:2017-11-21 16:39:01      阅读:239      评论:0      收藏:0      [点我收藏+]

  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变量

原文:http://www.cnblogs.com/zhangyide/p/7873522.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!