Python issue record

Source: Internet
Author: User

Today, the Python group sees a problem.

python2.7:

  

  'Hello'] 
  Print L
  Print x

python3.4:

  

'Hello'   
  Print (L) print (x)

Both can print out

    L = ['h'e'l ' L ' ' o ']

But only python2.7 can print out the value of the variable x:

  ' o '

  

>>> L = [x forXinch 'Hello']>>>PrintL ['h','e','L','L','o']>>>Printx o>>> 

python3.4 shows that the x variable is not defined

  

   >>> L = [x forXinch 'Hello']>>>Print(L) ['h','e','L','L','o']>>>Print(x) Traceback (most recent): File"<pyshell#2>", Line 1,inch<module>Print(x) nameerror:name'x'  is  notdefined>>> 

Is such a problem, I through pycharm single-step debugging, found that python2.7 after the completion of the list parsing statements, the variable x still exists.

In python3.4 , after performing the list parsing, the variable x disappears.

Below is the result that I use pycharm separately to debug in different environment

python2.7:

python3.4:

I think this might be a case of python3.4 based on security considerations to avoid variables taking up memory.

On the other hand, it also guarantees that the use of variables in the latter case does not occur in the event of a wrong variable.

2016-03-28 13:26:34

Python issue record

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.