0420笔记
- Python dir() 函数
dir() 函数不带参数时,返回当前范围内的变量、方法和定义的类型列表;带参数时,返回参数的属性、方法列表。
dir() # 获得当前模块的属性列表
注意⚠️ dir(_ _ builtins _ _) 有两个小横线 - \ (在行尾时) 续行符
print(" \n\
7 \n\
8")
0421笔记
- 循环语句
counts = 3
while counts > 0:
print("今天打打王者")
counts = counts - 1
counts 变量
counts - 1 值
- break语句
- 生成随机数
import random
answer = random.randint(1,10) - 短路逻辑
0 or 1
1
0 and 1
0
1 or 2
1
1 and 2
2 - 运算符优先级
0429笔记
- 分支:if
if condition:
statement(s)
if condition:
statement(s)
else:
statement(s)
if condition1:
statement(s)
elif condition2:
statement(s)
elif condition3:
statement(s)
...
if condition1:
statement(s)
elif condition2:
statement(s)
elif condition3:
statement(s)
...
else:
statement(s)
statement(a) if condition else statement(b)
🌰
a = 2
b = 8
small = a if a < b else b
print(small)
- 循环:while