Python variable,

Source: Internet
Author: User

Python variable,

I. What are variables?

A variable is a memory object that stores data. The stored content can be dynamically changed. Defining a variable is equivalent to applying for an access space object with an address (variable name) to the memory to store data and facilitate data query and computation.

 

Ii. variable name rules

1. Variable names can only contain letters, numbers, and underscores. The variable name can start with a letter or underscore and cannot start with a number. For example, you can name the variable abc_1, but cannot name it ABC.

2. Variable names cannot contain spaces. You can use underscores to separate multiple words. For example, the variable name My_name is feasible, and the variable name My name will lead to an error.

3. keywords and function names reserved by python cannot be used as variable names. For example, using print as variable names is not allowed.

4. The variable name should be as short and descriptive as possible. It can be expressed by the TUO peak body. The variable name should be as short as possible and accurate as possible.

5. Variable names in python are case-sensitive. For example, Name and name are two different variable names.

 

3. How to define variables

Defining a variable in python is simple. Because python is a weak type language, defining a variable does not need to declare the variable type. Directly assigning a value to the variable is equivalent to defining a variable, the variable type matches the value type. NOTE: If only one variable is written and no value is assigned, python considers this variable undefined.

For example, >>> name = "Tom" indicates to define a variable named name. The variable value is "Tom" and the variable type is string.

 

Iv. Constants

In python, there is no syntax for defining constants. It is usually represented by a fully capitalized variable name, which is only a kind of prompting effect, for example, AGE = 22 (essentially a variable ).

 

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.