python实用案例教程第四章-python 入门到实践第四章案例

"""这是第四章的案例题"""

magicians = ["alice","david","carolina","eric","alex"] #创建一个列表

mes = "see you happy." #赋值一个字符串给变量

for magician in magicians:#一个for循环 ,":"告诉python下一行是循环的第一行

print(magician + " , " + mes)

print("see you anange " + " " + magician + ". " )

print("thank you ,everyone .that was a great magic show!")

for value in range(1,5):# 打印出数字组列表

print(value)

number = list(range(1,6))# 使用list 函数将rang 的组生产列表

print(number)

enev = list(range(0,11,2))

print(enev)

"""

squers = []

for value in range(1,11):

square = value**10

squers.append(square)

print(squers)

"""

"""

squers = []

for value in range(1,11):#使用for 循序遍历range 函数内生产的数组

squers.append(value**2)#使用列表方法“append”新增数字到列表中

print(squers)

"""

squers = []

for i in range(1,101):

squers.append(i)

print(squers)

print(min(squers))

print(max(squers))

print(sum(squers))

print(len(squers))

a = ["alex" ,"bbb"]

print(a)

players = ["charles","alex","cryets","eric","join"]

"""

print(players[1:4])#切片列表中第2个到第4个元素

for i in players[:3]:

print(i.title())

newplayers = players[:]#切片裂变中的所有元素给新的列表(保存了副本)

print(newplayers)

"""

nnewplayers = players #不是切片副本复制,关联

print(nnewplayers)

players.append("testa")

nnewplayers.append("testb")

print(players)

print(nnewplayers)

你可能感兴趣的:(python实用案例教程第四章-python 入门到实践第四章案例)