A few notes on the Python variable

Source: Internet
Author: User
A few notes on the Python variable

Python supports a variety of data types, within a computer, you can think of any data as an "object", and variables are used in the program to point to these data objects, the variable is assigned to the data and variables to associate.

  • A variable is a reference to a Memory object;
  • Variable has no type, object has type;
  • Python is a dynamic type language, and at any point in time, an object reference can re-reference a different object (which can be a different data type) whenever needed;
  • When an object reference to a data does not exist, Python automatically garbage-collects it;

In Python, if you want to use a variable, you don't need to declare it in advance, you just need to assign a value to the variable when you use it. In particular, it is emphasized that it is necessary to assign a value to a variable as long as it is used .

  • In Python, the role of "=" is to bind an object reference to an object in memory
  • Assigning a variable x = y is the variable x pointing to the real object, which is what the variable y points to. Subsequent assignment of the variable y does not affect the direction of the variable x.

Type (): View the data type of the object referenced by the variable;

ID (): View the memory address of the object referenced by the variable;

A few notes on the Python variable

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.