Python standard built-in functions and python type built-in functions

Source: Internet
Author: User

Python standard built-in functions and python type built-in functions

Python provides some built-in functions for basic object types: cmp (), repr (), str (), type () and ('') Operators equivalent to repr ().

(1) type ()

The usage of type is as follows:

Type (object)

Accept an object as a parameter and return its type. The returned value is a type object.

>>> Type ('R') <type 'str' >>>> type (3) <type 'int' >>>> type (5 )) <type 'type'>

(2) cmp ()

The built-in function cmp () is used to compare two objects, obj1 and obj2. If obj1 is greater than obj2, a positive integer is returned. If it is smaller than, a negative integer is returned. If it is equal to, 0 is returned.

>>> A, B = 4, 12 >>> cmp (a, B)-1 >>> B = 4 >>> cmp (a, B) 0 >>>, B = 'xyz', 'abc'> cmp (a, B) 23

(3) str (), repr ()

You can easily obtain the object content, type, numeric attributes, and other information in string mode. The str () function makes the string readable, while the string obtained by repr () can be used to obtain the object again.

>>> Str (1) '1' >>> str (2e4) '2017. 0' >>> repr ([20000,]) '[,]'

 

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.