Python instance sharing for variable assignment operations

Source: Internet
Author: User
This article mainly introduced the Python programming variable assignment operation, combined with the instance form Analysis Python assignment, the displacement, the multivariate assignment operator and so on related operation use skill, needs the friend to refer to the next

The examples in this paper describe the variable assignment operation of Python programming. Share to everyone for your reference, as follows:


#coding =utf8 ' "Python is primarily assigned by an equal sign (=). Instead of assigning a value directly to a variable, the assignment in Python assigns the object's reference (not the value) to the variable. "#赋值运算符Int =12float=12.2string=" Hello "list=[1,2," Hell "]touple= (4," hell ") dictionary={' one ': 1, ' both ': 2,} ' PYT The Hon Assignment statement does not return a value. ' #add = (int=int+2) #错误的赋值语句add =int=int+2 #python支持链式赋值print add,int "' Increment assignment: The equals sign and an operator combination and re-assigns the result to the left variable. "Int+=10print" The int+10= ", Intfloat-=0.2print" the float-0.2= ", Floatint*=5print" the Int *5= ", Intint/=5print" the Int/5= ", Intint%=5print" the int%2= ", Intint **=2print" the int **= ", intint<<=2# left shift two-bit print" The int <<2= ", intint>>=2# two-bit print "The int>>2=", Intint &=10# by phase and print "The Int &10=", intint ^=3# bitwise take counter print "the Int^3= ", Intint |=3# by phase or print" The int|3= ", int#list add list+=[' Ewang ']print" the List: ", list# multiple assignment a=b=c=d=e=f=8print A, b , c,d,e,f "' Multivariate assignment: assigns multiple variables at the same time. When you assign a value in this way, the objects on both sides of the equal sign are tuples. Usually tuples need to be enclosed in parentheses (). Parentheses are optional, and for code readability, it is recommended to add the parentheses ' x,y,z=4,8," Ewang " #为了代码可读性, it is recommended to use the parentheses print x, Y, z (x, y) = (4,8, "Ewang") print X,y,z#python's multivariate assignment to allow the value of two variables to be exchanged without an intermediate variable (x, Y) = (y,x) print x, y 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.