python循环同时满足2个条件_python(2)-条件判断、循环等

1.字符

str=‘sweet’

str.upper() 字符全大写 SWEET

str.title() 字符首字母大写 Sweet

str.lower() 字符全小写 sweet

2.if条件判断

(1)if a==b or/and c!=d 方式

(2)if a in/notin list1 方式

举例如下:

banned_users = ['andrew', 'carolina', 'david']user = 'marie'

if user not in banned_users:

print(user.title() + ", you can post a response if you wish.")

结果:Marie, you can post a response if you wish.

(3)if-elif-else

(4)list=[]列表为空,if list 返回False

3.用户输入和while循环

3.1 函数input()的工作原理

函数input() 让程序暂停运行,等待用户输入一些文本。获取用户输入后,Python将其存储在一个变量中,以方便你使用。

message = input("Tell me something, and I will repeat it back to you: “)

print(message)

结果:

Tell me something, and I will repeat it back to you: H

你可能感兴趣的:(python循环同时满足2个条件_python(2)-条件判断、循环等)