Python基础——列表、元组、字典
!/usr/bin/python
-- coding: UTF-8 --
this is about lists
list1 =[‘python’,’java’,’android’,’sql’] #define a lists
list2 =[‘python’,’java’,’android’,’sql’] #define another lists
print list1[0]
a= cmp(list1,list2)
print a
list1.insert(1,’c++’) #insert a new list in the lists
print list1
list1.append(‘c’) #insert a new list in the last of the lists
print list1
list1.reverse() #reverse the lists
print list1
list1.extend(list2) #extend a new lists into the list
print list1
this is about tup
tup1 = (‘pychsics’,’chemistry’,1997,2000) #define the frist tup
tup2 =(1,2,3,4,5) #define the twice tup
print “tup1[0]:”,tup1[0] #printout the tup1[0]
print “tup2[1:5]:”,tup2[0:4] #print out the tup2[1-5]
tup3 =tup1+tup2
print tup3 #you can connect the tup1 and tup2 but you can’t alter them
del tup1 #delete tup1
print tup2*3
print 3 in tup2 #output a boolen if number in the tup or not
for x in tup2:
print x
this is about dictionary
dict1 = {‘name’:’qianbingbing’,’age’:24,’tel’:12343554}
print dict1[‘name’]
print dict1[‘age’]
print dict1[‘tel’]
del dict1[‘name’]
print dict1
dict1.clear()
print dict1
del dict1
dict2 = {‘name’:’qianbingbing’,’age’:24,’tel’:12343554}
print len(dict2)
更多相关文章
- 代码中设置drawableleft
- android 3.0 隐藏 系统标题栏
- Android开发中activity切换动画的实现
- Android(安卓)学习 笔记_05. 文件下载
- Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
- 技术博客汇总
- android 2.3 wifi (一)
- AndRoid Notification的清空和修改
- Android中的Chronometer