Python学习第七天

#!/usr/bin/python

#filename :test7.py


# Part one:Python list


list1 = ['physics','chemistry',1997,2000];

list2 = [1,2,3,4,5,6,7];


print ("list1[0]:",list1[0])

print ("list2[1:5]:",list2[1:5])



print ("list1[2]:",list1[2])

list1[2] = 10000

print ("after update the value list1[2]:",list1[2])


print (list1)

del list1[2]

print ("after deleting value at index 2:")

print (list1)


print (len(list1))

print (list1+list2)


print (list1*4)

print (2000 in list1)


for x in list1:

print (x)


print (list1.append(1))

print ("new list1 : ",list1)


print ("list1.count(1) :",list1.count(1))

print ("list1.index(1) :",list1.index(1))



# Part two : Python tuple

tup1 = ('physics','chemistry',1997,2000)

tup2 = (1,2,3,4,5,6)

tup3 = 'a','b','c','d'

print (tup1)

print (tup2)

print (tup3)


tup4 = ()

tup5 = (50,)

print (tup4)

print (tup5)


# the values of tuple are not allowed changing

#tup1[0] =100


tup6 = tup4 + tup5;

print (tup6);


del tup6

print ("after deleting tup:")

#print (tup6)    # is not defined


print (len((1,2,3)))

print ((1,2,3)+(4,5,6))


print ('abc',-4.21,18+6.6,'xyz')

x,y = 1,2

print ('value of x , y :',x,y)




你可能感兴趣的:(Python学习第七天)