# ===== CodeLab: Python 数据类型与变量详解 =====
# 来源: https://aoerliang.dpdns.org/articles/python-data-types
# 以下代码片段按文章出现顺序拼接, 共 4 段

# ----- 片段 1 (python) -----
name = "小林"        # str
age = 25            # int
height = 1.75       # float
is_student = True   # bool

print(type(name))   # <class 'str'>
print(type(age))    # <class 'int'>

# ----- 片段 2 (python) -----
a, b = 10, 3
print(a / b)    # 3.3333333333333335
print(a // b)   # 3 整除
print(a % b)    # 1 取余
print(a ** b)   # 1000 乘方

# 浮点数精度:二进制无法精确表示 0.1
print(0.1 + 0.2)  # 0.30000000000000004

# ----- 片段 3 (python) -----
def show(value):
    if value:
        print(f"{value!r} 为真")
    else:
        print(f"{value!r} 为假")

show(0)          # 0 为假
show("")         # '' 为假
show([])         # [] 为假
show(None)       # None 为假
show("Python")   # 'Python' 为真

# ----- 片段 4 (python) -----
s = "42"
n = int(s)          # 字符串 → 整数
f = float("3.14")   # 字符串 → 浮点数
print(str(n) + "!") # 整数 → 字符串

print(isinstance(n, int))   # True
print(isinstance(f, (int, float)))  # True 数字家族
