Python Base 2 variables

Source: Internet
Author: User

Chapter Content

    1. Defined
    2. Variable rules
    3. Assigning values to variables
Defined

Variables are used to store information for subsequent program calculations. Variable information is present in memory. Variable declaration

name = "Cathy Wu"

The code above declares a variable named: Name, and the value of the variable name is: "Cathy Wu"

Variable rules
    • 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 ']

Attention:

2name, name of Cathywu, $name error.

_name ______name name is correct.

Cannot take an underscore-this represents a minus sign.

It is better not to use Chinese to make variable names.

There are two types of naming plans:

    1. Gfofoldboy Hump Naming method

Hump nomenclature: When a variable name or function name is a unique identifier consisting of one or more words, the first word starts with a lowercase letter, and the first letter of the second word is capitalized or the first letter of each word is uppercase.

    • Small Hump method is usually identified by small hump method. The Hump method means that in addition to the first word, the first letter of the word is capitalized. such as int mystudentcount; Variable Mystudentcount The first word is all lowercase and the first letter of the following word is capitalized.
    • The big hump method compared to the small hump method, the big hump method (that is, Pascal named) the first word of the initial letter is capitalized. Commonly used for class names, function names, properties, namespaces. For example, public class Databaseuser;
    1. Underline Gf_of_oldboy

Python suggests underlining.

Assigning values to variables

In Python, the equal sign = is an assignment statement, you can assign any data type to a variable, the same variable can be repeatedly assigned, and can be different types of variables, the variable itself is the type of non-fixed language called Dynamic language. A variable A is assigned to another variable B. Example of an assignment principle: a = ' abc ' b = a A = ' xyz ' Print b the last line to print out the contents of the variable B is ' abc ' or ' xyz '? If we understand mathematically, we will mistakenly conclude that B and a are the same, and should be ' XYZ ', but actually the value of B is ' abc ', let us execute the code in one line, we can see exactly what happened: execute a = ' abc ', the interpreter created the string ' ABC ' and variable A, and pointed a to ' ABC ':

Execute B = A, the interpreter creates the variable B and points B to the string ' ABC ' that points to a:

Execute a = ' xyz ', the interpreter creates the string ' xyz ' and changes the point of a to ' XYZ ', but B does not change:

So, the result of printing variable B at last is ' ABC ' naturally.

Reference pages

Http://www.cnblogs.com/alex3714/articles/5465198.html

Python Base 2 variables

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.