马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
python的变量使用前要先赋值。等号(=)是赋值的意思,左边是变量的名字,右边是值。
可以理解成把名字贴在值的上边。
>>> myteacher = '小甲鱼' # 给变量myteacher赋值'小甲鱼'
>>> yourteacher = myteacher # 给变量yourteacher赋值变量myteacher的值,即yourteacher = '小甲鱼'
>>> yourteacher = '黑夜' # 再给变量yourteacher赋值'黑夜'
>>> print(myteacher) # 打印myteacher的值,即小甲鱼
小甲鱼
>>> myteacher = '小甲鱼' # 给变量myteacher赋值'小甲鱼'
>>> yourteacher = myteacher # 给变量yourteacher赋值变量myteacher的值,即yourteacher = '小甲鱼'
>>> myteacher = '黑夜' # 再给变量myteacher赋值'黑夜'
>>> print(yourteacher) # 打印yourteacher的值,即小甲鱼
小甲鱼
>>> print(myteacher) # 打印myteacher的值,即黑夜
黑夜
变量A = 变量B ,变量B的值已经赋给变量A后,
只要后面没有对A重新赋值,不管后面变量B的值怎么变化,都不会影响变量A的值
>>> B = [1,2,3,4]
>>> B[1]
2
>>> B[3]
4
>>> B[1], B[3] = B[3], B[1]
>>> B
[1, 4, 3, 2]
B[1] = B[3] =4
B[3] = B[1] =2
看上去是4和2的调换了位置,实际是赋值发生了变化
|