The four-story Python variable parsing

Source: Internet
Author: User

Variables in 1,python language differ from other language variables

Variable-------------> Exactly what is changing???


>>> x=12 x points to the memory unit where 12 is located
>>> y=13 y points to the memory unit where 13 is located
>>> Print X
12
>>> Print Y
13

In Python, a variable is a small tag of a piece of memory

X=y means that x points to a memory unit that points to Y (similar to a pointer in C), so you cannot modify the data that it points to a memory cell by using a variable, and you can change its point by assigning a value.

The variable is the memory point, not the data it points to.

>>> x=12
>>> x=13
>>> print x The data in the memory unit pointed to by 12 is still 12
13


>>> x=13
>>> ID (x)
37841736 (Memory tab 1)
>>> x=12
>>> ID (x)
37841760 (Memory tab 2)
>>> y=13-------give Y the address in the memory unit where 13 is located, that is, the memory unit where Y points to 13
>>> ID (y)
37841736 (Memory label 3 and memory label 1 same)


X=y principle: X---->| 12

Y---->|-------13

In the C language, the variable allocates memory address once

In Python, when a new variable is generated, the newly allocated memory stores the data and modifies the data of the variable to point to the x=100


No data type of variable in 2,python

What type of value is assigned, and what type is the variable?

>>> x=12
>>> type (x)
<type ' int ' >
>>> y=12.5
>>> type (y)
<type ' float ' >

>>> z= ' www.baidu.com '

>>> type (z)
<type ' str ' >

The four-story Python variable parsing

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.