The difference between some keywords in python

Source: Internet
Author: User

I.. raw_input and Input

Input and Raw_input can read the console inputs, but input and raw_input are different when working with numbers.

1, when the input is a pure number
    • Input returns a numeric type, such as Int,float
    • Raw_inpout return String type, String type

2. When input is a string expression

    • Input computes the numeric expression in the string, and Raw_input does not.
    • For example, enter "57 + 3":
    • Input will get an integer 60
    • Raw_input will get the string "57 + 3"

    • For example, enter "5,4,9,2,8,3":
    • Input will get a tuple of integers
    • Raw_input will get the string ' 5,4,9,2,8,3 '

ii. The difference between sort and sorted

Sort () is an order of itself, no return value

Sorted () has a return value, returns a well-ordered copy, the original value does not change

Iii. The difference between continue and break

both continue and break jump out of the loop statement. The difference is that continue jumps out of the loop, break jumps out of the loop

iv. The difference between Xrang and range

The range and xrange usages are exactly the same, and the difference in generating a list,xrange with range is a generator.

In order to generate a large number sequence, using xrange will be much better than range performance, because there is no need to open up a large amount of memory space.

The difference between some keywords in 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.