[python]列表的操作

发布时间:2020-03-30 23:55:34 作者:望天儿先生
来源:网络 阅读:293

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)

推荐阅读:
  1. python中zip函数的用法
  2. dialog的使用方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

python 列表

上一篇:Git - warning: push.default is unset

下一篇:关于图片轮播图的一个简单实例 以及实例中发现问题

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》