Python基础之赋值与注释

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!
'''
posted @ 2020-01-08 16:27  油饼er  阅读(285)  评论(0编辑  收藏  举报