Python built-in function:

Source: Internet
Author: User

Built-in functions

View Details: Https://docs.python.org/3/library/functions.html#next

ABS () absolute value

All () When all values are true: None,flase, empty, False

A= all([' 1 ',])
Print (a) True

Any () is true when any one of the values is true.

Bin () View integer binary

BOOL () View Boolean type: Ture/flase

Chr () converts an integer to a computer-recognized character:

A = chr (81)
Print (a) Q can be used for verification code

Ord () converts a character to a number:

Ord (' A ')
print (a)
65
Random: Generates a stochastic number.
Import Random
Print (Random.randint (1,99))

Dict (): Generates a dictionary.
Dir (): View the actions that the object can use.
A =dir (111)
print (a)

[' __abs__ ', ' __add__ ', ' __and__ ', ' __bool__ ', ' __ceil__ ', ' __class__ ', ' __delattr__ ', ' __dir__ ', ' __divmod__ ', ' __doc__ ', ' __eq__ ', ' __float__ ', ' __floor__ ', ' __floordiv__ ', ' __format__ ', ' __ge__ ', ' __getattribute__ ', ' __getnewargs__ ', ' _ _gt__ ', ' __hash__ ', ' __index__ ', ' __init__ ', ' __int__ ', ' __invert__ ', ' __le__ ', ' __lshift__ ', ' __lt__ ', ' __mod__ ', ' __ Mul__ ', ' __ne__ ', ' __neg__ ', ' __new__ ', ' __or__ ', ' __pos__ ', ' __pow__ ', ' __radd__ ', ' __rand__ ', ' __rdivmod__ ', ' __reduce ' __ ', ' __reduce_ex__ ', ' __repr__ ', ' __rfloordiv__ ', ' __rlshift__ ', ' __rmod__ ', ' __rmul__ ', ' __ror__ ', ' __round__ ', ' __ Rpow__ ', ' __rrshift__ ', ' __rshift__ ', ' __rsub__ ', ' __rtruediv__ ', ' __rxor__ ', ' __setattr__ ', ' __sizeof__ ', ' __str__ ', ' __sub__ ', ' __subclasshook__ ', ' __truediv__ ', ' __trunc__ ', ' __xor__ ', ' bit_length ', ' conjugate ', ' denominator ', ' from_ ' Bytes ', ' imag ', ' numerator ', ' real ', ' to_bytes ']

Divmod: Divides and returns the remainder.

Enumerate: Add the target number.
wjh={
' Wjh1 ':' 11 ',
' Wjh2 ':' 22 ',
}
Enumerate (wjh,2):
Print (I,V)

2 WJH2
3 WJH1

Eval (): The function evaluates the string str as a valid Python expression and returns the result of the calculation.
R = 1
Print eval ()
r =1
Print (eval (' r + 1 '))
Float (): floating-point number.
Help (): helps.
ID (): View memory address.
Input (): insert.
int (): integer.
Hex (): 16 binary conversion.
Len (): Length.
List (): Lists
Min (): Minimum value
Max (): Maximum value
Oct (): Octal
Open (): Opening file
Print (): printing
Pow (): Second party
Import Math
Pow (2,2)
Print (a)


Range (): Define Quantity
Reversed (): Invert
Set (): Defines a unique collection
Round (): approximately, approximately equal to
Sorted (): Sort
STR (): string
SUM (): Sum
Tuple (): tuple
Type (): Types
VARs (): View built-in methods
Class A:
foo=100
VARs (a)
Print (b)


Zip (): combines the array into a list.
Map (): The map function maps the specified sequence according to the provided function.
 lil=[22,23,24, " 
New_li=map (lambda x:x + 100,lil)
Li = list (New_li)
print (LI)


Filter (): Filter
li1=[,44]
def fuc (x):
If x>22:
Return True
Else
Return False
new_li=Filter (FUC,LI1)
Print (list (new_li))
Lambda expression

When learning conditional operations, for simple if else statements, you can use the ternary operation to indicate that:

12345678 # 普通条件语句if 1 == 1:    name = ‘wupeiqi‘else:    name = ‘alex‘  # 三元运算name = ‘wupeiqi‘ if 1 == 1 else ‘alex‘

For simple functions, there is also an easy way to represent a lambda expression

123456789101112131415 # ###################### 普通函数 ####################### 定义函数(普通方式)def func(arg):    return arg + 1  # 执行函数result = func(123)  # ###################### lambda ######################  # 定义函数(lambda表达式)my_lambda = lambda arg : arg + 1  # 执行函数result = my_lambda(123)

The existence of Lambda means a concise representation of simple functions

Open file Operations:









Python built-in function:

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.