目录

  • 1. 花式赋值
  • 1.1 链式赋值
  • 1.2 交叉赋值
  • 1.3 交叉赋值(解压缩)
  • 2. 注释
  • 2.1 单行注释
  • 2.2 多行注释

1. 花式赋值

1.1 链式赋值

a = 10
b = 10
c = 10
print(a, b, c)

结果为:

10 10 10

链式赋值:

a = b = c = 10
print(a, b, c)

结果为:

10 10 10

1.2 交叉赋值

x = 123
y = 456

temp = x
x = y
y = temp
print(x, y)

结果为:

456 123

交叉赋值:

x = 123
y = 456

x, y = y, x
print(x, y)

结果为:

456 123

1.3 交叉赋值(解压缩)

height_of_nick, weight_of_nick, age_of_nick = 149, 180, 12
print(height_of_nick, weight_of_nick, age_of_nick)

结果为:

149 180 12

2. 注释

2.1 单行注释

# a = 2       # 注释此行,不执行
b = 3
print(b)      # 打印b

单行注释一般注释在一行的后面,如果是语句块,则注释于语句块前

ctrl + / 注释多行,再次输入则取消注释

2.2 多行注释

"""
我要被注释了
我要注被释了
"""

'''
It is annotation!
It is annotation!
'''