[python]列表的操作
1
magicians = ['alice', 'david', 'carolina']
for magician in magicians:
print(magician)
for magician in magicians:
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!")
2
for value in range(1,5):
print(value)
numbers=list(range(1,6))
print(numbers)
numbers=list(range(1,10,3)) ##3是步长
print(numbers)
squares = []
for value in range(1,11):
square = value**2
squares.append(square)
print(squares)
squares = []
for value in range(1,11):
squares.append(value**2)
print(squares)
squares = [value**2 for value in range(1,11)]
print(squares)
3
digits=[1,2,3,4,5,6,7,8,9]
print(min(digits))
print(max(digits))
print(sum(digits))
4
n2 = [num for num in range(1,21,2)]
print (n2)
n3 = [num for num in range(3,31)]
for num1 in n3:
if num1 % 3 == 0:
print(num1)
n4 = [num**3 for num in range(1,11)]
print (n4)
player = ['charls','martina','michael','florence','eli']
print(player[0:3])
print(player[:2])
print(player[2:])
print(player[-3:])
player1=player[:] ##复制
print(player1)
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341