Home  >  Article  >  Backend Development  >  python variable type-how to assign values ​​to single or multiple variables (example analysis)

python variable type-how to assign values ​​to single or multiple variables (example analysis)

乌拉乌拉~
乌拉乌拉~Original
2018-08-13 15:05:305662browse

In this article, I will talk about the variable types in python, hoping to help you who are exposed to python.

The variable stores the value in memory. This means that when a variable is created, a space is created in memory. Based on the data type of the variable, the interpreter allocates the specified memory and determines what data can be stored in the memory. Therefore, variables can specify different data types, and these variables can store integers, decimals, or characters.

Variable assignment: Variable assignment in Python does not require a type declaration.

## This variable is created in memory, including the identification of variables, names and data information.

Each variable must be assigned before use, and the variable will be created after the variable assignment.

The equal sign (=) is used to assign a value to a variable. The left side of the equal sign (=) operator is a variable name, and the right side of the equal sign (=) operator is the value stored in the variable.

Next let me give an example:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
counter = 222 # 赋值整型变量
miles = 1000.0 # 浮点型
name = "John" # 字符串
 
print counter
print miles
print name

The results of this example are as follows:

100
1000.0
John

By From this we can know that 100 1000.0 "john" is assigned to three variables: counter, miles, and name respectively.

##Multiple variable assignments: Python allows you to assign values ​​to multiple variables at the same time, for example:

a=b=c=1

In the above example, create an integer object with a value of 1, three variables are 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 respectively, and the string object "john" is assigned to variable c.


The above is an explanation of variable assignment and multiple variable assignment in python. I hope it will be helpful to you who are learning python.

                   

The above is the detailed content of python variable type-how to assign values ​​to single or multiple variables (example analysis). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn