1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python为数组里的每一个元素加1的代码

python为数组里的每一个元素加1的代码

时间:2021-08-31 11:58:24

相关推荐

python为数组里的每一个元素加1的代码

在内容闲暇时间,将开发过程较好的内容段珍藏起来,下面内容段是关于python为数组里的每一个元素加1的内容,应该能对各位有帮助。

#!/usr/bin/env python

#

# [SNIPPET_NAME: Generate modified list]

# [SNIPPET_CATEGORIES: Python Core]

# [SNIPPET_DESCRIPTION: How to generate a modified list by iterating over each element of another list]

# [SNIPPET_AUTHOR: Scott Ferguson <scottwferg@>]

# [SNIPPET_LICENSE: GPL]

first_list = range(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

result = [x + 1 for x in first_list] # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

print result

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。