1、集合框架
list = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
print list
list[0] = 'wanghanlin'
print list
list2 = [ 'abcd', 786 , 2.23, 'john', 70.2 ]
print list2
tuple = ( 'abcd', 786 , 2.23, 'john', 70.2 )
print tuple
print tuple[0:2]
dictionary = {'name':'wanghanlin','age':19,'Character':'A',8:'eight'}
print dictionary
print dictionary['name']
print dictionary[8]
set = {1,2,3,4,5}
list3 = [1,2,3,4,5]
print list3
list3.append(6)
print list3
print list3[0]
tuple = (1,2,3,4,5)
print tuple[0]
print set
range = range(10,20)
print range
2、逻辑语句
var = 150
if var == 100:
print "var:100"
elif var == 150:
print "var:150"
else:
print "var:none"
count = 0
while count < 5:
print count," is less than 5"
count = count + 1
else:
print count," is not less than 5"
print count
a = [1,2,3,4,4]
hellworld = list('helloworld')
print hellworld
print a[0]
a.append(6)
print a
b = (1,2,3,4,4)
print b
b2 = ()
b2 = (5,4,3,2,1)
print b2
print len(b2)
c = {1:'one',2:'two',3:'three',4:'four',5:'five'}
print c[2]
c[6] = "eight"
print c[6]
print c
c[3] = "the modified three!"
print c[3]
print c
d = {1,2,3,4,"string",4,"string"}
print "d集合的长度:",len(d)
print "------a------"
for i in a:
print i
print "------b------"
for i in b:
print i
print "------c------"
for i in c:
print i
print "------d------"
for i in d:
print i
print "-------range------"
for i in range(11):
print i+52
print "username" in a
print 1 in a
3、函数
def myfunc(mylist):
print "正在运行myfunc函数"
mylist.append([1,2,3,4])
print "已经运行了myfunc函数!"
a = [55,56]
myfunc(a)
print a
def apply(name, age = 35):
print "apply方法调用成功!"
print "Name:",name
print "Age:",age
apply("zhangsan",35)
apply("zhangsan")
def huge(name,*args):
print "Name:",name
for i in args:
print "arguments:",i
huge("zhangsan",1,'A',"nvpengyou")
lamb_func = lambda x,y:x+y
res0 = lamb_func(5,3)
print res0
func2 = lambda x,y:[x+1,y+1]
res1 = func2(4,9)
print res1
def myown(x,y):
return x+y
print myown(1,2)
def myown2(x,y):
return [x+1,y+1]
print myown2(4, 6)