table of Contents
if the judge
Single-branch structure
dog_name = 'dachangtui' # 一个=是赋值 if dog_name == 'dachangtui': # 两个=是两端比较是否相等 print('干它') if dog_name == 'fenggou': print('干掉它') ''' 自上而下运行 if 条件: print('条件成立干嘛干嘛') # 条件成立才会执行该段代码,不成立不执行该段代码 .... '''
Two-branch structure
''' if 条件: print('条件成立干嘛干嘛') # 条件成立才会执行该段代码,不成立不执行该段代码 else: print('条件不成立干嘛干嘛)# 条件不成立才会执行该段代码,成立不执行该段代码 ''' dog_name = '' if dog_name =='fenggou': print('干掉它') else: print('干它')
Multi-branch structure
Two or more branched structure
# 1. 身高>1.5 全票 # 2. 身高1.2-1.5 半票 # 3. 身高<1.2 免票 height = 1.3 price = 100 if height > 1.5: print('门票价格:', price) elif height > 1.2: print('门票价格:', price * 0.5) # elif height < 1.2: # print('门票价格:', price * 0) else: print('门票价格:', price * 0) ''' if 条件: print('条件成立干嘛干嘛') # 条件成立才会执行该段代码,不成立不执行该段代码 elif 条件: print('if条件不成立走这条') elif 条件: ... else: print('条件不成立干嘛干嘛)# 条件不成立才会执行该段代码,成立不执行该段代码 '''
for loop
Loop: Repeat thing
# range方法
print(list(range(10))) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] # 默认从0开始,10结束,默认步长为1,顾头不顾尾
print(list(range(1,10))) # [1, 2, 3, 4, 5, 6, 7, 8, 9] # 1表示开始,10表示结束,默认步长为1,顾头不顾尾
print(list(range(1,10,2))) # [1, 2, 3, 4, 5, 6, 7, 8, 9] # 1表示开始,10表示结束,2表示步长,顾头不顾尾
Formatting Output: string concatenation
name = 'nick'
print(name + ' handsome')
print('{name} handsome ') # {name} handsome
print(f'{name} handsome ') # 字符串前面加上f,{}就有了特殊意义,name不是普通的字符,他会去引用变量
for loop
for i in [1, 2, 3, 4, 5, 6, 7, 8, 9]: # 把列表内部的值循环打印
print(i)
print(f'8月{i}日刷牙')
nested for loop: completed all the inner loop, the outer loop will go once, each time into the outer loop, the inner loop will be reset
# j --> 1,2,3,...12
for j in range(1,13): # j =1 j = 2... 控制的是月份
# print(j)
for i in range(1, 32): # 控制的是日
print(f'{j}月{i}日刷牙')
for + break: the cycle is interrupted in advance
for j in range(1,13): # j =1 # j = 2 # j = 3
# print(j)
if j == 3:
break # 中断循环
for + continue: skip cycle
for i in range(101): # 打印0-100
if i == 51:
continue # 跳出本次循环,不执行下面的代码,然后直接进入下一次循环
print(i)
Reptiles and the three-part song
send request
Analytical data
save data
The essence of reptiles
- Communication process analysis site.
- Find analyze data comes from.
- Anti-climb policy analysis target site.
- Preparation of attacks based on anti-climb policy target site, access to data.
json module
是一种第三方的数据格式.
json.dumps() # 把python数据格式转成json数据格式
json.loads() # 把json数据格式转成python数据格式