码迷,mamicode.com
首页 > 其他好文 > 详细

列表和元组操作.py

时间:2016-09-12 18:56:02      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

magicians = [alice,david,carolina]        #for循环操作
for magician in magicians:                      #不要遗漏冒号
    print(magician)
    print( magician.title()+, that was a great trick)
    print("I can‘t wait to see your next trick," + magician.title()+".\n")
    
print(Thank you,everyone.That was a great magic show!)


for value in range(1,5):                        #使用range 函数
    print(value)

numbers = list(range(1,6))
print(numbers)

even_numbers = list(range(2,11,2))
print(even_numbers)

squares =[]
for value in range(1,11):
    square = value**2
    squares.append(square)
print(squares)

squares = [value**2 for value in range(1,11)]
print(squares)

digits = [1,2,3,4,5,6,7,8,9,0]                  #简单统计计算
print(min(digits))
print(max(digits))
print(sum(digits))


players = [charles,martina,michael,florence,eli]# 切片
print(players[0:3])
print(players[1:4])
print(players[:3])
print(players[2:])
print(players[-3:])

players = [charles,martina,michael,florence,eli]

print("Here are the first three players on my team:")   #for循环遍历切片
for player in players[:3]:
    print(player.title())

my_foods = [pizza,falafel,carrot cake,]
friend_foods = my_foods[:]


my_foods.append(cannali)
friend_foods.append(ice creame)

print(My favourate foods are:)
print(my_foods)


print("\nMy friend‘s favourate foods are:")
print(friend_foods)

print("The first three iteams in the list are:")
print(my_foods[0:4])



dimensions= (200,5)                         #遍历元组所有值
print(dimensions[0])
print(dimensions[1])
for dimension in dimensions:
    print(dimension)


dimension = (200,50)                        #修改元组变量
print("Original dimensions:")
for dimension in dimensions:
    print(dimension)

dimensions = (400,10)
print("\nModified dimensions:")
for dimension in dimensions:
    print(dimension)

 

列表和元组操作.py

标签:

原文地址:http://www.cnblogs.com/dws-love-jfl-1314/p/5865759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!