for value in range(1,5):
print(value)
numbers=list(range(1,6))#生成列表
print(numbers)
squares=[]
for value in range(1,11):
square=value2
squares.append(square)
print(squares)
print(min(squares))
print(max(squares))
squares=[value2 for value in range(1,11)]#列表解析
print(squares)
players=[‘charles’,‘martina’,‘michael’,‘florence’,‘eli’]
print(players[0:3])
print(players[2:])
for player in players[:3]:
print(player.title())
my_foods=[‘pizza’,‘falafel’,‘carrot cake’]
friend_foods=my_foods[:]#复制列表
print(“My favorite foods are:”)
print(my_foods)
#元组,修改元组被禁止
dimensions=(200,50)
print(dimensions[0])
for dimension in dimensions:
print(dimension)
cars=[‘bmw’,‘audi’,‘toyota’,‘subaru’]
for car in cars:
if car ==‘bmw’:
print(car.upper())
else:
print(car.title())
age_0=18
age_1=22
print(age_0>21 and age_1>21)
if ‘bmw’ in cars:
print(True)
else:
print(False)
age=18
if age<4:
price=0
elif age < 18:
price=5
elif age < 65:
price=10
elif age >=65:
price=15
print(‘you cost’+’ '+str(price))
python2day
最新推荐文章于 2024-03-02 11:12:35 发布