Python built-in functions

Source: Internet
Author: User

1. All ([-1, 0, 1]) #判断是否全是不等于0的数

2. Any ([ -1,0,1]) # has a number not 0 returns true any ([]) return False

3.ascii ([1, 2, ' Open plug ']) #进行ascii conversion

4.bin (1) #十进制转换为二进制

5.bool (1) #判断是否为真

6. A = bytes (' abcde ', encoding = ' utf-8 ') #abcde code is UTF-8 encoded into byte form

7.

b = ByteArray (' abcde ', encoding = ' utf-8 ') #可以进行修改的字节形式

Print (b[1])

B[1] = 100
Print (b)

8.def Sayhi ():p

Callable (Sayhi) # represents a function that can be accessed

9. chr (98) # Convert the number to ASCII

10.ord (' d ') # convert ASCII to Digital

11.code = ' For I in Range ':p rint (i) '

EXEC (code) # converts letters into executable code

12.dir View Internal methods

13.divmod (5, 2) #相除返回余数

14.calc = lambda n:print (n)

Calc (5)

Res =filter (lambda n:n>5, range) #过滤器

res = [Lambda n:n*2 for N in range (10)]

For I in Res:

Print (i)

Reduce

Import Functools

res = Functools.reduce (lambda x,y:x+y, Range (1, 10))

Print (RES)

16.frozenset ([1, 2, 3, 4, 5]) #变成不可变列表

17.globals () #整个程序的变量

Hash (' Alex ') #生成一个特有数学编号

Hex (255) #转化为16进制

20.locals ()

def test ():

A = 333

Print (Locals ()) #找到局部程序的变量

Test ()

Oct (8) #转换成8进制

22.pow (3, 5) # How many Times Square

Repr # converted to a string

c = 1

Repr (c)

24.reversed () inversion

25.round (1.3333, 2) #四舍五入 Reserve Two-bit natural number

Slice #切片

D = Range (20)

D[slice (2, 5)]

27.sorted ()

A = {6:2, 8:0, 1:4, -5:6, 99:11, 4:22}

Print (sorted (A.items (), key = Lambda x:x[1]) # Sorted by value ()

28.zip generated zipper one by one corresponding

A = [1, 2, 3, 4, 5, 6]

b = [' A ', ' B ', ' C ', ' d ']

H = Zip (A, B)

For i in H:

Print (i)

Python built-in functions

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.