Variable assignment operation instance analysis in Python programming and python instance analysis

Source: Internet
Author: User
Tags python list

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.

Related Article

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.