Python脚本速成

0_python基础

1. for 循环

for i in range(100):
    print(f"我爱学习,第{i+1}次")

2. while 死循环 【无限循环】

num = 0
while True:
    num = num + 1
    print(f"我爱学习,第{ num }次")

    if num == 30:
        break
    time.sleep(1)

3. if 如果 【判断】

a = 10
if a > 5:
    print("你真棒")
else:
    print("你真垃圾")

if a < 5:
    print("你真弱")
elif a > 9:
    print("你真棒")
else:
    print("你很一般")

4. split() 分割

a = "张三,李四,王五,马六"
b = a.split(",")
print(b[1])

5. set() 列表去重复

a = ["张三","李四","王五","王五"]
b = list(set(a))
print(b)

6. len() 求列表的数量

a = ["张三","李四","王五","马六"]
print(len(a))

7. 读写文件

with open("./数据/账号信息.txt","r",encoding="utf8") as f:
    读入的文本 = f.read()
    print(读入的文本)

with open("./数据/被写出的文本.txt","w",encoding="utf8") as f:
    f.write("顶替顶替枯要55555")

with open("./数据/被写出的文本.txt","a",encoding="utf8") as f:
    f.write("顶替顶替枯要66666")
with open("./数据/被写出的文本.txt","a",encoding="utf8") as f:
    f.write("\n顶替顶替枯要777777")