码迷,mamicode.com
首页 > 编程语言 > 详细

python类型

时间:2014-12-29 18:37:41      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:python类型

每天学习一点点,通过例子

字符串

>>> word=‘asdf‘

>>> word[:2]

‘as‘

>>> word[1:]

‘sdf‘

>>> a= [x for x in ‘abcdsf‘ if x not in ‘abc‘]

>>> a

[‘d‘, ‘s‘, ‘f‘]


链表

ques = [‘a‘,‘b‘,‘c‘]

 ans = [‘1‘,‘2‘,‘3‘]

for q,a in zip(ques,ans)

print q,a


字典

>>> person ={‘name‘:‘xiaoli‘,‘age‘:21,‘sex‘:‘male‘}

>>> person

{‘age‘: 21, ‘name‘: ‘xiaoli‘, ‘sex‘: ‘male‘}

>>> person[‘name‘]

‘xiaoli‘

>>> person[‘name‘] = ‘xiaohong‘

>>> person

{‘age‘: 21, ‘name‘: ‘xiaohong‘, ‘sex‘: ‘male‘}

>>> del person[‘sex‘]

>>> person

{‘age‘: 21, ‘name‘: ‘xiaohong‘}

>>> list(person.keys())

[‘age‘, ‘name‘]

>>> for k,v in person.items():

...     print (k,v)

... 

(‘age‘, 21)

(‘name‘, ‘xiaohong‘)

元组

>>> a =123,456,‘asd‘

>>> a

(123, 456, ‘asd‘)

>>> a[0]

123

>>> b = a,‘ertr‘,‘dfg‘

>>> b

((123, 456, ‘asd‘), ‘ertr‘, ‘dfg‘)

>>> c = ([1,2,3],[3,2,1])

>>> c

([1, 2, 3], [3, 2, 1])




python类型

标签:python类型

原文地址:http://itsoar.blog.51cto.com/8915220/1597344

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!