Python Basics "Eighth" variable

Source: Internet
Author: User

1. Variable definition:

Naming the data, the name of the data is called a variable

2. Variable format:

[variable name] = [value]

(Note: The name in a Python variable cannot use the following characters because it has been referenced within Python

And,as,assert,break,class,continue,def,del,elif,else,except,exec,false,finally,

For,from,global,if,import,in,is,lambda,not,none,or,pass,print,raise,return,try,

True,while,with,yield)

Print variables:

>>print (variable)

Reference variable:

Use variable names directly

Cases:

    Define a variable named "Test" with a value of string "Python    test">>> test='python test'    Print test    python test

Variables refer to the variables themselves:

    >>> test=test+str (1)    print  test    python test1       + = str (1)    Example:     >>> test='python test'    >>> Test + = str (1)     >>> test    'python test1'

Third, the memory point of the variable

If I define a variable data = ' Alan ' and then assign data to string (string = data) then will the value of data change when I modify the string?
Let's look at the following diagram:

Comments:

1. When you create data = ' Alan ', the variable creates a space in memory to hold the value and the corresponding relationship, such as this memory space address is 010101

2. When string = data, the string variable points itself to the memory ' Alan ' memory address of 010101

3. However, when string = ' Lisa ', string will re-open a memory space to store ' Lisa ' memory address 010102 without modifying data

Instance:

>>> data ='Alan'>>> string =Data>>>string'Alan'>>> ID (data)//view the address in data memory45990656 >>> ID (string)//to view the address in a string memory45990656 >>> string ='Lisa'//re-assigning a value to a string>>> Data//See if the value of data changes, but it does not change'Alan'>>> ID (data)//View the memory address of data45990656 >>> ID (string)//View the memory address of a string45913152

Python Basics "Eighth" 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.