# Note: The built-in function ID () can return an object's identity, and the return value is an integer. This integer usually corresponds to the location of the object in memory, but this is related to the specific implementation of Python, which should not be defined as a definition of identity, which is not accurate enough, the most accurate or the memory address. The # is operator is used to compare the identities of two objects, the equals sign compares the values of two objects, and the built-in function type () returns the type of an object following precedence lists the built-in functions needed to master print (ABS ( -1)) # 1 Take absolute value
Print (All ([2, 3, 4, ' SSS ', ' True ')) # The value inside is all ture, then returns True if the value inside is null also returns True
Print (Any (' 3 ')) #里面的值只要有一个为Ture, select return True if the value inside is empty, then return false
Print (bytes (' Hello, Albert ', encoding= ' Utf-8 ') # Convert the utf-8 encoded string into binary
Print (Callable (' d '. Strip)) # To determine if the value inside is an iterative type that can be added (), such as ' abc '. strip (), Max (), etc.
Print (BIN) #十进制转二进制
Print (Oct) #十进制转八进制
Print (hex) #十进制转十六进制
Print (bool (0)) #0, None, null Boolean value False
res= ' Hello Egon '. Encode (' Utf-8 ') # Unicode is encoded according to Utf-8, resulting in bytes type
Res=bytes (' Hello Egon ', encoding= ' Utf-8 ') # ibid.
Print (RES)
def func ():
Pass
Print (Callable (' aaaa '. Strip)) #判断某个对象是否是可以调用的, callable refers to a function that can be executed in parentheses
Print (CHR) #按照ascii码表将十进制数字转成字符
Print (Ord (' Z ')) #按照ascii码表将字符转成十进制数字
Print (dir (' abc ')) # to see which methods can be called through points under an object
Output:
[' __add__ ', ' __class__ ', ' __contains__ ', ' __delattr__ ', ' __dir__ ', ' __doc__ ', ' __eq__ ', ' __format__ ', ' __ge__ ', ' __ getattribute__ ', ' __getitem__ ', ' __getnewargs__ ', ' __gt__ ', ' __hash__ ', ' __init__ ', ' __init_subclass__ ', ' __iter__ ', ' __le__ ', ' __len__ ', ' __lt__ ', ' __mod__ ', ' __mul__ ', ' __ne__ ', ' __new__ ', ' __reduce__ ', ' __reduce_ex__ ', ' __repr__ ', ' __ Rmod__ ', ' __rmul__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __subclasshook__ ', ' capitalize ', ' casefold ', ' center ', ' Count ', ' encode ', ' endswith ', ' expandtabs ', ' find ', ' format ', ' Format_map ', ' index ', ' isalnum ', ' isalpha ', ' isdecimal ', ' IsDigit ', ' isidentifier ', ' islower ', ' isnumeric ', ' isprintable ', ' isspace ', ' istitle ', ' isupper ', ' join ', ' ljust ', ' Lower ', ' lstrip ', ' Maketrans ', ' partition ', ' replace ', ' rfind ', ' rindex ', ' rjust ', ' rpartition ', ' rsplit ', ' rstrip ', ' SPL It ', ' splitlines ', ' startswith ', ' strip ', ' swapcase ', ' title ', ' Translate ', ' upper ', ' Zfill ']
Print (Divmod (1311,25)) # outputs a meta-ancestor, containing quotient and remainder (52,11)
Eval highlights, can be used for file read and write operations
# Take the expression of the word characters and run it and get the result of the expression
Res=eval (' {' name ': ' Egon ', ' Age ': 18} ')
Print (Res,type (res))
Output: {' name ': ' Egon ', ' age ': <class ' dict ' >
# Application of eval in file
With open (' Db.txt ', ' R ', encoding= ' utf-8 ') as F:
S=f.read ()
Dic=eval (s)
Print (Dic,type (DIC))
Print (dic[' Egon ')
# eval OK. The string expression that is opened by the default file is taken out and run, and the result of the expression is converted into the original data type, which makes it easier to read and write.
Fset=frozenset ({frozenset}) #集合是一个可变类型, can make immutable collections, Fset has no. Add method.
Print (len ({' X ': 1, ' Y ': 2}) #{' x ': 1, ' Y ': 2}.__len__ ()
Obj=iter (' Egon ') # ' Egon '. __iter__ ()
Print (Next (obj)) #obj. __next__ ()
Print (Next (obj)) #obj. __next__ ()
Print (ITER (obj)) #obj. __next__ ()
Output results
2
E
G
<str_iterator Object at 0x00000000021e7160>
Python built-in method summary