if语句
复制代码
1
2
3
4
5
6
7# if后注意有冒号 age = 22 if age > 18: print("age is", age) print("adult")
if-else语句
复制代码
1
2
3
4
5
6
7
8
9
10# if 和 else 后有冒号 age = 22 if age > 18: print("age is", age) print("adult") else: print("age is", age) print("teenager")
if-elif-else语句
复制代码
1
2
3
4
5
6
7
8age = 3 if age >= 18: print('adult') elif age >= 6: print('teenager') else: print('kid')
判空
复制代码
1
2
3
4# 只要x是非零数值、非空字符串、非空list等,就判断为True,否则为False。 if x: print('True')
input的返回值是str
复制代码
1
2
3
4
5
6
7
8s = input('birth: ') # 返回值是str,需要使用int函数转为整型 birth = int(s) if birth < 2000: print('00前') else: print('00后')
最后
以上就是成就冷风最近收集整理的关于【05】条件判断判空input的返回值是str的全部内容,更多相关【05】条件判断判空input内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复