Python基础——列表、元组、字典

来源:互联网 发布:二战苏联远东部队知乎 编辑:程序博客网 时间:2024/06/13 03:09

!/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)

0 0
原创粉丝点击