wei/unit_4/first_numbers.py

25 lines
532 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#range从知道的数字开始到达指定的数字停止不包含停止数字
for value in range(1,5):
print(value)
#可以使用range创建列表
numbers = list(range(1,6))
print(numbers)
#range可以指定步长如从1开始到达11结束步长为2
even_numbers = list(range(1,11,2))
print(even_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)