Built-in function one of Python basics

Source: Internet
Author: User

Built-in functions are much more, just record the next part today.

ABS ()

Seek absolute value

>>> ABS ( -10.1)

All () is true, parameters are iterative

>>> All ([12,3,4,5, None]) False

Any () is true, it is true

>>> any ([12,3,4,5, None]) True

BOOL () Boolean value

>>> bool (1) True>>> bool (0) False

ASCII () automatic execution of __repr__ objects

Chestnuts:

class Foo:     def __repr__ (self):         return " 444 "  = ASCII (Foo ())print(n)print(Bin (5))print (Oct (9))print(hex) Result:4440b1010o110xf

Bin () Turn binary

Oct () goto octal

Hex () Turn hex

Data type:

0b means binary

0o means octal

0x indicates hexadecimal

Bytes () Converts a string to a byte type

Bytes () generally followed by encoding= ' character encoding, for example: bytes (' Li Jie ', encoding= ' utf-8 ')

Chestnuts:

>>> bytes (' kanji ', encoding='UTF8') b'  \xe6\xb1\x89\xe5\xad\x97'>>> bytes (' kanji ', encoding='gbk') b'\xba\xba\xd7\xd6' 

Encoding UTF-8: A kanji account of three bytes

Encoding GBK: A kanji account of two bytes

Bytecode deserialization, using the str command:

Chestnuts:

Name=bytes (' li Jie ', encoding='UTF-8')print (name) new_name=str (bytes (name), encoding='UTF-8')Print (new_name)

Results:

b'\xe6\x9d\x8e\xe6\x9d\xb0' li Jie

Built-in function one of Python basics

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.