Variable assignment operation instance analysis in Python programming and python instance analysis
This article describes how to assign values to variables in Python programming. We will share this with you for your reference. The details are as follows:
# Coding = utf8''' in Python, values are assigned by equal signs (=. The value assignment in Python does not directly assign a value to a variable, but instead assigns the reference (not a value) of the object to the variable. ''' # Value assignment operator Int = 12 Float = 12.2 String = "hello" List = [, "hell"] Touple = (4, "hell ") dictionary = {'one': 1, 'two': 2,} ''' the value assignment statement of python does not return values. ''' # Add = (Int = Int + 2) # incorrect value assignment statement add = Int + 2 # python supports chain assignment print add, int ''' Incremental Value assignment: The equals sign is combined with an operator and the calculation result is assigned to the variable on the left. '''Int + = 10 print "The Int + 10 =", IntFloat-= 0.2 print "The Float-0.2 = ", floatInt * = 5 print "The Int * 5 =", IntInt/= 5 print "The Int/5 =", IntInt % = 5 print "The Int % 2 = ", intInt ** = 2 print "The Int ** =", IntInt <= 2 # shift left two print "The Int <2 = ", intInt> = 2 # print "The Int> 2 =", IntInt & = 10 # print by phase "The Int & 10 = ", intInt ^ = 3 # reverse print by bit "The Int ^ 3 =", IntInt | = 3 # by phase or print "The Int | 3 = ", int # List addition List + = ['ewang'] print "The List:", List # multiple values a = B = c = d = e = f = 8 print, b, c, d, e, f''' multivariate Value assignment: assign values to multiple variables at the same time. in this way, the objects on both sides of the equal sign are tuples. the tuples are usually enclosed in parentheses. parentheses are optional. We recommend that you add parentheses '''x, y, z =, "ewang" # For code readability, we recommend that you use parentheses print x, y, z (x, y, z) = (4, 8, "ewang") print x, y, z # The Python multivariate assignment method can realize the print x, y = (y, x) print x, y without the need for intermediate variables to exchange the values of two variables (x, y)
For more Python-related content, refer to this topic: getting started with Python and advanced classic tutorial, Python string operation skills summary, and Python list) operation Skills summary, Python coding skills summary, Python data structure and algorithm tutorial, Python function usage skills summary, and Python file and directory operation skills Summary
I hope this article will help you with Python programming.