模块
def greet(name): return f"Hello, {name}!" value = 42import my_module print(my_module.greet("Alice")) print(my_module.value)from my_module import greet, value print(greet("Bob")) print(value)
Last updated
def greet(name):
return f"Hello, {name}!"
value = 42import my_module
print(my_module.greet("Alice"))
print(my_module.value)from my_module import greet, value
print(greet("Bob"))
print(value)Last updated
import math
print(math.sqrt(25))
print(math.sin(math.pi / 2))import os
print(os.getcwd()) # 获取当前工作目录
os.mkdir("new_directory") # 创建新目录import datetime
now = datetime.datetime.now()
print(now)
print(now.year)import random
print(random.randint(1, 10)) # 生成 1 到 10 之间的随机整数