一、格式化输出
eg:现在有一下需求,让用户输入name,age,job,hobby然后输出如下所示:
---------------info of Alex Li---------------
Name:Alex Li
Age:22
Job:Teacher
Hobbie:girl
---------------End---------------
代码:
ame = input("请输入姓名:")
age = input("请输入年龄:")
job = input("请输入工作:")
hobbie = input("请输入爱好:")
data = """
---------------info of %s---------------
Name = %s
age = %s
job = %s
hobbie = %s
-----------------------------------------
"""%(name,name,age,job,hobbie)
print(data)
二、运算符
2.1 算术运算
2.2 比较运算
2.3 赋值运算
2.4 逻辑运算
三、while 循环
while 条件:
循环体
index = 1
while index < 11:
if index == 8:
pass
else:
print(index)
index += 1
print("算完啦")
in and not in
可以判断***字符串是否出现在***字符串中
eg:
content = input("请输入您的评论:")
if "苍老师" in content:
print("您评论的内容不合法")
else:
print("评论成功")