# 动态类型,无需声明
agent_id = 007 # int
code_name = "Bond" # str
is_active = True # bool
price = 19.99 # float
print(f"Agent: {code_name}")
if is_active and agent_id == 7:
print("Access Granted")
elif agent_id == 0:
print("Root User")
else:
print("Access Denied")
# 类似数组,但更灵活
tools = ["nmap", "wireshark"]
# 添加元素
tools.append("sqlmap")
# 遍历
for tool in tools:
print(f"Loading {tool}...")
# 哈希表/JSON风格
server = {
"ip": "192.168.1.1",
"port": 8080,
"os": "Linux"
}
print(server["ip"])
server["status"] = "Online"
# 循环5次 (0 到 4)
for i in range(5):
print(i)
# While 循环
power = 10
while power > 0:
power -= 1 # 自减
try:
# 尝试执行危险操作
x = 1 / 0
except ZeroDivisionError:
# 捕获错误
print("Error: Infinity detected")
finally:
print("Cleanup done.")
import random
import time
def generate_password(length=8):
chars = "abcdef012345"
return "".join(random.choice(chars) for _ in range(length))
# 调用函数
pwd = generate_password(12)
print(f"Generated Token: {pwd}")