What is a python variable? On variable assignment in Python variables

Source: Internet
Author: User
python variablesis a knowledge point that can't be bypassed in programming, Python variables, the code works correctly, and the value is especially important. variablesstored in-memory value, which means that when a variable is created, it is in memory open up a spaceBased on variablesData type, the interpreter allocates the specified memory and determines what data can be stored in memory, so variablesYou can specify a different Data Type, these variables can be storing integersdecimalOr character

assigning values to variables

variable Assignments in Python do not require a type declaration, and each variable is created in memory, including information about the identity, name, and data of the variable. Each variable must be assigned before it is used, and the variable will not be created until the variable is assigned.

The equals sign (=) is used to assign a value to a variable.

The left side of the equals sign (=) operator is a variable name , and the right side of the equals sign (=) operator is the value stored in the variable . For example:

#!/usr/bin/python#-*-Coding:utf-8-*-counter = +         # Assignment integer variable miles = 1000.0        # float name = "John"                # string Print Co unter Print miles Print name

In the above example, 100,1000.0 and "John" are assigned to the COUNTER,MILES,NAME variable respectively.

Executing the above program will output the following results:

100

1000.0

John

assigning values to multiple variables

Python allows you to assign values to multiple variables at the same time. For example:

A = b = c = 1

The above example creates an integer object with a value of 1 and three variables allocated to the same memory space.

You can also specify multiple variables for multiple objects. For example:

A, b, C = 1, 2, "John"

In the above example, two integer objects 1 and 2 are assigned to variables A and B, and the string object "John" is assigned to variable C. Identification method: The left and right sides of the equal sign as characters, each corresponding.

For more information, please visit the PHP Chinese Web Python tutorial section.

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.