#range 函数
num=[i for i inrange(1,11)]print(num)
num1=list(range(2,11,2))print(num1)
squares=[]for i inrange(1,11):'''square=i**2
squares.append(square)'''
squares.append(i**2)print(squares)print(max(num),min(num),sum(num))#切片print(num[:],'\n',num[:5],'\n',num[-4:])#元组
dimensions=(200,50)print(dimensions[0])print(dimensions[1])# dimensions[0]=90 wrong syntax#更改元组需要重新整体赋值
dimensions=(90,50)print(dimensions[0])print(dimensions[1])#if 条件语句==布尔达表达式
cars=['a','b','c']for car in cars:if car=='a':#注意冒号print("i don't want this car!")else:print('nice')#用and检查多个条件 相当于“&&”
age1=20
age2=44print(age1>5and age2<9)#增加可读性 age1>5 加括号#or=="||"print((age1>=20)or(age2<5))#in/not in 检查特定值在/不在list中print(5in num)print(5notin num)print(11in num1)print(11notin num1)#if——elif——else
age=12if age<4:
price=0elif age<18:
price=5elif age<65:
price=10elif age>=65:
price=5print("Your price is "+str(price))'''if后若一个条件成立则跳过剩余条件
else有时可省略
else可能会导致出错,因为只要不满足if elif 都会执行else 所以少用
尽量用 if elif''''''运行一个代码块 if——elif
多个代码块 一系列if语句'''
ETcolor=['yellow','red','green']#if 'green' in ETcolor:# print('you have got 5 points')for color in ETcolor:if color=='green':print('you have got 5 points')elif color=='yellow':print('you have got 10 points')elif color=='red':print('you have got 15 points')#elif 后面要跟条件#if 处理list
toppings=[]if toppings:#可以直接判断列表是否为空for topping in toppings:print('Adding'+topping+'.')else:print('Are you sure you want a plain pizza?')'''practise'''
list1=['admin','a','boob','c','d']for name in list1:if name=='admin':print('hello',name,'would you like to see a status report?')else:print('hello',name,'thank you for logging in again')if list1:print(list1)else:print('We need to find some users!')
current_users=['Neil','Jessic','John','Olive']
new_users=['lourl','Olive','JOHN','Roy']
current_users_lower=[user.lower()for user in current_users ]for user1 in new_users:if user1.lower()in current_users_lower:print('Has been used')else:print('Can be used')
```python
在这里插入代码片