变量
x = 3
#给x赋值
x是变量,3是值
print(x)
#输出x的值
变量可以由字母、数字和下划线组成,但不能以数字打头。
iloveyou1314 = 1314
#此代码有效
520baby =520
#此代码无效
Python 3支持中文变量
幸运数 = 8
print(幸运数)
变量的值可变
name = "小甲鱼"
print(name)
name = "老乌龟"
print(name)
变量的值取决于上一次赋值操作
x = 3
y = 5
y = x
print(y)
x = y = 3
x
y
x = 3
y = 5
z = x
x = y
y = z
print(x, y)
x = 3
y = 5
x, y = y, x
print(x, y)
字符串
“小甲鱼” “老乌龟”
单引号(文本),双引号(文本),三引号
print('I love China.')
print("I love China.")
print('Let's go!')
#此代码无效
print('"Life is short, you need Python."')
转义字符\
print('\"Life is short, Let\'s learn Python.\"')
\n 换行符
print("I love Python. \nI love FishC.")
0 条评论