Python常用语法
一、表达式 if ... else
if name == "alex" and pwd == "cmd":
print("欢迎,alex!")else: print("用户名和密码错误")if else 语句的三元运算
|
1
|
result = 值1 if 条件 else 值2 |
如果条件为真:result = 值1
如果条件为假:result = 值2
二、、表达式for loop
最简单的循环10次
|
1
2
3
4
5
6
|
#_*_coding:utf-8_*___author__ = 'Alex Li'for i in range(10): print("loop:", i ) |
三、while loop
有一种循环叫死循环,一经触发,就运行个天荒地老、海枯石烂。
海枯石烂代码
|
1
2
3
4
5
|
count = 0while True: print("你是风儿我是沙,缠缠绵绵到天涯...",count) count +=1 |
其实除了时间,没有什么是永恒的,死loop还是少写为好
posted on 2018-08-30 14:33 Richer_wang 阅读(158) 评论(0) 收藏 举报
浙公网安备 33010602011771号