import调用
from hello import *
import hello
hello.hello("sakura")
时间
from datetime import datetime
def time():
dt = datetime.now()
print(f"{dt.year}年{dt.month}月")
变量拼接字符串
print("ya~hello~" + name)
print('1234,{}'.format(name))
print(f'1234,{name}')
replace&json解析为数组
def ai_talk(question):
return question.replace('你','我').replace('不','').replace('吗','').replace('?','!').replace('?','!')
def tianqi(city):
url = "http://t.weather.sojson.com/api/weather/city/101030100"
res = requests.get(url)
tq_json = json.loads(res.text)
wendu = tq_json["data"]["wendu"]
print(wendu)
print(f'{city}:温度 {wendu}')
输入&append&min&lambda
guess = input('guess a number from 1 to 10')~
scores.append((answer,guess))
print(min(scores, key=lambda x:x[1]))
split
arr = str.split("<")
for order,s in enumerate(arr,-1):
if("os" in s):
print("第",order,"个",s)~