Python Basics (2): Python Variables and constants

Source: Internet
Author: User

Today look at the variables and constants of Python: Python3 C:\test.py

first, let's talk. The interpreter executes the Python process:

1. Start the Python interpreter (in memory)

2. Read the C:\test.py content from the hard disk into memory (this step is the same as the text editor)

3. Execute code that reads into memory

If you want to permanently save your code, you need to use the file
If you want to debug your code, you need to use an interactive approach

What is a variable?

Change , core in and change Quantity: Measurement, measurement, expression is a state

Definition of a variable

Ps:

Level = 1

Level: Variable name =: assignment operator 1: value

To define a rule:

Variable names can only be any combination of letters, numbers, or underscores

The first character of a variable name cannot be a number

The following keywords cannot be declared as variable names

[' and ', ' as ', ' assert ', ' Break ', ' class ', ' Continue ', ' Def ', ' del ', ' elif ', ' Else ', ' except ', ' exec ', ' finally ', ' for ', ' F ' Rom ', ' Global ', ' if ', ' import ', ' in ', ' was ', ' lambda ', ' not ', ' or ', ' pass ', ' print ', ' raise ', ' return ', ' try ', ' while ', ' WI Th ', ' yield ']

Python has a resource recovery mechanism

Ps:

Name= ' Lln ' # ' Lln ' reference count of this value +1
Name= ' Llh ' # ' LLH ' reference count of this value +1, ' Lln ' reference count of this value-1
The value of the reference count or the value of the body is bound to a variable named 0, the Python interpreter will periodically reclaim their free space.

Three important components of a variable definition:

ID Address
Type types
Value values

Constant

Constant amount of
There is no specific way to define constants in Python, usually with uppercase variable names representing constants
Just a hint of the effect
Ps:

LLN_BODY=50 (Nature or variable can be changed value)

Small knowledge points: the way you define them is usually a camel's body and underline.

Ps:

LlnOldboy = 50

lln_oldboy = 50 

Python Basics (2): Python Variables and constants

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.