The second built-in function module 3.9 Python

absolute value abs #

all #Return True if bool(x) is True for all values x in the iterable.If the iterable is empty, return True.

>>> a = [1,2,3]

>>> all(a)
True
>>> a.append(0)
>>> a
[1, 2, 3, 0]
>>> all(a)
False

>>> asset_list=[600,700,None]
>>> all(asset_list)
False

any #Return True if bool(x) is True for any x in the iterable.If the iterable is empty, return False.

ascii #Return an ASCII-only representation of an object, ascii ( "China") returns " '\ u4e2d \ u56fd'"

bin # returns an integer binary format

>>> bin(10)
'0b1010'

bool # determines a data structure is True or False, bool ({}) that returns False, because it is empty dict

>>> a = [1,2,3]

>>> bool(a)
True
>>> bool ([])
False
>>> bool({})
False

bytearray # to byte become bytearray, modifiable array

>>> str = "alex"
>>> str
'alex'
>>> str[1]
'l'
>>> str[1:3]
'le'
>>> a = "中国".encode("gbk")
>>> a
b'\xd6\xd0\xb9\xfa'
>>> a[0]
214
>>> a[1]
208
>>> a[1]
208
>>> a[1]=3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bytes' object does not support item assignment

>>> bytearray(a)
bytearray(b'\xd6\xd0\xb9\xfa')
>>> b=bytearray(a)
>>> b
bytearray(b'\xd6\xd0\xb9\xfa')
>>> b[1]
208
>>> b[1]= 200
>>> b
bytearray(b'\xd6\xc8\xb9\xfa')
>>> b.decode("gbk")
'秩国'

bytes # bytes ( "China", "gbk")

Callable # judge whether an object can be called

chr # Returns ascii characters corresponding to a number, such as chr (90) in the ascii Returns 'Z'

>>> chr(65)
'A'

classmethod # when using object-oriented, now ignored

Something compile #py interpreter own use, ignore

complex # seek the complex, less than the average person

copyright # useless

useless credits #

delattr # when using object-oriented, now ignored

dict # creates an empty dict

dir # returned object callable attributes

>>> dir(a)

divmod # quotient and a remainder of the division is returned, such divmod (4,2), the result (2, 0)

enumerate # Returns the index and the list of elements, such as d = [ "alex", "jack"], the enumerate (d), to give (0, 'alex') (1, 'jack')

>>> a = ["alex","jack"]
>>> enumerate(a)
<enumerate object at 0x10ffebaf0>
>>> for i in enumerate(a): print(i)
...
(0, 'alex')
(1, 'jack')

eval # string may be in the form of list, dict, set, tuple, which is converted to the original data type.

# names = ["alex","jack",'kevin']
#
# f = open("eval_test","w")
# f.write(str(names))
f = open("eval_test")
d = eval(f.read())

print(type(d))
print(d[2])

exec # format code string, and performing de-sense, such as exec ( "print ( 'hellworld')"), which will Explanations string and performing

exit # Exit program

for filter # list, dict, set, tuple, etc. iterables filter, filter (lambda x: x> 10, [0,1,23,3,4,4,5,6,67,7]) was filtered off All values ​​greater than 10

>>> list(filter(lambda x:x>10,[0,1,23,3,4,4,5,6,67,7]))
[23, 67]

float # turn to floating point

format # useless

frozenset # to become a collection of non-modifiable

 

getattr # when using object-oriented, now ignored

globals # print the value in the global scope

hasattr # when using object-oriented, now ignored

hash #hash function

help

hex # 10 returns a hexadecimal representation of the decimal, hex (10) to return '0xa'

View the memory address of the object id #

input

int

isinstance # determines a type of data structure, such a determination is not fronzenset, isinstance (a, frozenset) returns True or False

>>> isinstance(b,frozenset)
True
>>> isinstance(b,set)
False

issubclass # when using object-oriented, now ignored

iter # to a data structure becomes an iterator, the iterator speak to understand

only

list

locals

map # map (lambda x: x ** 2, [1,2,3,43,45,5,6,]) output [1, 4, 9, 1849, 2025, 25, 36]

>>> a
{1, 2, 3}
>>> map(lambda x:x**2,a)
<map object at 0x1100dc350>
>>> list(map(lambda x:x**2,a))
[1, 4, 9]

selecting the maximum value max #

memoryview # Most people do not ignore

for the minimum min #

next # Builder will be used, now ignored

When using object-oriented object #, now ignored

oct # Returns the decimal representation of the octal

open

ord # Returns ascii characters corresponding to decimal 10 ord ( 'a') to return 97,

print

property # when using object-oriented, now ignored

quit

range

repr # useless

a list can be reversed # reverse

round # 4 can be rounded decimal 5 into integers, round (10.15,1) to give 10.2

set

setattr # when using object-oriented, now ignored

slice # useless

sorted

staticmethod # when using object-oriented, now ignored

str

sum # sum, a = [1, 4, 9, 1849, 2025, 25, 36], sum (a) to give 3949

super # when using object-oriented, now ignored

tuple

type

vars # returns the properties of an object, an object-oriented will understand

zip # 2 or more can makes up a list, a = [1, 4, 9, 1849, 2025, 25, 36], b = [ "a", "b", "c", "d" ],

list(zip(a,b)) #得结果 
[(1, 'a'), (4, 'b'), (9, 'c'), (1849, 'd')]


Guess you like

Origin www.cnblogs.com/kissfire008/p/11746252.html