跳转至

第三章:基础语法

注释

# 单行注释

"""
多行注释
可以写很多行
"""

'''
也可以用单引号
'''

变量

# Python 是动态类型语言
name = "Python"
age = 30
price = 99.99
is_active = True

# 多重赋值
a, b, c = 1, 2, 3

# 交换变量
a, b = b, a

数据类型

# 数字
integer = 42
float_num = 3.14
complex_num = 1 + 2j

# 字符串
s1 = 'hello'
s2 = "world"
s3 = f"{s1} {s2}"  # f-string 格式化

# 布尔
flag = True

运算符

# 算术运算符
+ - * / // % **

# 比较运算符
== != > < >= <=

# 逻辑运算符
and or not

# 成员运算符
in not in

# 身份运算符
is is not

输入输出

# 输出
print("Hello, World!")
print(f"Name: {name}, Age: {age}")

# 输入
name = input("请输入姓名: ")
age = int(input("请输入年龄: "))