C Programmer's doubts about Python

Source: Internet
Author: User

1.if/else,try,while does not produce a new scope

Unlike Java,c, Python has only class and module to create new variable scopes, such as the following code, which makes the JAVA,C programmer very puzzled.

>>if A is None:

>> x=3

>>print x

2. Why Python variables look like there are no type restrictions, such as the following code

>>a= ' String '

>>a=111

In the Python world, everything is an object, even a function. So the above code is actually an object reference, the right value is the generated object, that is, a point to a new object, so the code does not error. But there are still types of objects, such as

>>a= ' string ' +111 does not work because a string object cannot drink an integer object to add.

In the eyes of C + + programs, you can actually understand

Object *a= new Int (111);

Object *a= New String (' string ');

Can be seen as variable A can also be understood as a type, except that the type is general-purpose

3. Whether the function parameter is passed as a value or a reference

If a function receives a reference to a mutable object (such as a dictionary or a list), it can modify the original value of the object-the equivalent of passing the object through a "pass reference". If the function receives a reference to an immutable object, such as a number, character, or tuple,

You cannot modify the original object directly-it is equivalent to passing the object through a "pass value".

C Programmer's doubts about Python

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.