Appearance
...
Appearance
不教面向对象,够用就行
变量: name = "张三" age = 25 is_pass = True
字符串:
f"我叫{name},今年{age}岁" # f-string 最方便
text.strip() # 去空格
"hello" in text # 判断包含列表:
fruits = ["苹果", "香蕉"]
fruits.append("橘子")
fruits[0] # 取第一个
len(fruits) # 长度字典:
user = {"name": "张三", "age": 25}
user["name"] # "张三"
user.get("name") # 推荐,取不到返回 Noneif score >= 90:
print("优秀")
elif score >= 60:
print("及格")
for fruit in fruits:
print(fruit)def add(a, b):
return a + b
with open("data.txt", "r") as f:
content = f.read()try:
result = 10 / 0
except Exception as e:
print(f"出错了:{e}")不需要学面向对象、继承多态。 上面的足够写自动化了。