Python学习第七天
博客专区 > _liucui_ 的博客 > 博客详情
Python学习第七天
_liucui_ 发表于2年前
Python学习第七天
  • 发表于 2年前
  • 阅读 32
  • 收藏 1
  • 点赞 1
  • 评论 0

腾讯云 新注册用户 域名抢购1元起>>>   

摘要: http://www.runoob.com/python/python-dictionary.html 今天学习下list和元组

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




共有 人打赏支持
粉丝 17
博文 113
码字总数 46697
×
_liucui_
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: