Python (day1)-Variable Quiz

Source: Internet
Author: User

Here is a topic:

A = 3

b = A

A = 5

Print (A, B)

What is the value of the last output of the program, A/b?

Think about it first, and then we'll take a look at the correct answer:

The value of correct answer a is 5, the value of B is 3, why doesn't the value of B change with the value of a? Let's analyze Why:

Here we first introduce a function ID (), which can look at the memory address of the variable; OK, here's the analysis:

Split the program, assign 3 to a first, and then look at the memory address

Assign A to B, and then look at the memory address of B

As you can see, the memory addresses of B and a are the same

Assign 5 to A to see the memory address of a

You can see that A's memory address has changed and a points to a new memory address.

The entire process is as follows:

Python (day1)-Variable Quiz

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.