Python built-in functions 1

Source: Internet
Author: User

1.r=compile (S, "<string>", "exec")

Compile () compiles a string into Python code

2.exec (r) Execute Python code

3.eval ("8*6") eval ("") can only execute an expression, the execution of Eval () will have a return value, exec executes no return value.

4.filter and map

Filter (the function, which iterates over the object), returns a collection of elements that meet the criteria. Filter on an iterative object.

Map (a function, an iterative object) is equivalent to a for loop, processing each element and returning new processing results.

5.with open (' config ', ' R ') as F:

For lines in F: This is a one-line load operation that is more efficient than f.readlines () loading all the files into memory

6. Data with a value of false

0, None, "", [], {}, ()

7.all () and any ()

The two functions receive an object that can be iterated, and all () requires that all data in the object be true before returning true,any () requirements

Returns true if at least one data in the object returns True

8.bin () receive 10 binary converted into binary

Oct () decimal "octal"

Hex () decimal "hex"

9.utf-8 encoding A Chinese character is 3 bytes, GBK encoding a Chinese character is 2 bytes. One byte is 8 bits

n = bytes ("Kanji", encoding= "Utf-8")

Convert Kanji to byte type, n results differ from encoding settings

str1 = str (n,encoding= "Utf-8")

10.CHR () Convert the numbers in the ASCII code table to the corresponding characters

Ord () converts a character to a corresponding number () Gets the contents of the string type.

12.python Execution Process reads the contents of a file into a string loaded into memory

The 2.python compiler compiles strings into special code

3. Execute code

13.s= "Print (123)"

R = Compile (s, "<string>", "exec") python compile string into Python code

EXEC (R) Exec () can also receive execution string, no return value Python executes the compiled code string

S= "8*7"

Ret=eval (s) Python arithmetic expression and returns the result assigned to RET

Python built-in functions 1

Related Article

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: 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.