This article mainly introduces the variable assignment operation of Python programming, and analyzes the usage skills of Python assignment, displacement, multiple assignment operators and other related operations in the form of examples. Friends in need can refer to the examples of this article
Describes the variable assignment operation in Python programming. Share it with everyone for your reference, the details are as follows:
#coding=utf8 ''''' Python中主要通过等号(=)进行赋值。 Python中的赋值不是直接将一个值赋给一个变量, 而是将该对象的引用(并不是值)赋值给变量。 ''' #赋值运算符 Int=12 Float=12.2 String="hello" List=[1,2,"hell"] Touple=(4,"hell") Dictionary={'one':1, 'two':2, } '''''python的赋值语句不会返回值。''' #add=(Int=Int+2) #错误的赋值语句 add=Int=Int+2 #python支持链式赋值 print add,Int '''''增量赋值:等号和一个运算符组合一起并将计算结果重新赋值给左边的变量。''' Int+=10 print "The Int+10=",Int Float-=0.2 print "The Float-0.2=",Float Int*=5 print "The Int *5=",Int Int/=5 print "The Int/5=",Int Int%=5 print "The Int%2=",Int Int **=2 print "The Int **=",Int Int<<=2#左移两位 print "The Int <<2=",Int Int>>=2#右移两位 print "The Int>>2=",Int Int &=10#按位相与 print "The Int &10=",Int Int ^=3#按位取反 print "The Int^3=",Int Int |=3#按位相或 print "The Int|3=",Int #List加法 List+=['EWANG'] print "The List:",List #多重赋值 a=b=c=d=e=f=8 print a,b,c,d,e,f '''''多元赋值:将多个变量同时赋值. 采用这种方式赋值时,等号两边的对象都是元组. 通常元组需要用圆括号()括起来. 圆括号是可选的,为了代码的可读性,建议加上圆括号 ''' x,y,z=4,8,"ewang" #为了代码可读性,建议使用圆括号 print x,y,z (x,y,z)=(4,8,"ewang" ) print x,y,z #Python的多元赋值方式可以实现无需中间变量交换两个变量的值 (x,y)=(y,x) print x,y
The above is the detailed content of Example sharing on variable assignment operations in Python. For more information, please follow other related articles on the PHP Chinese website!