Python built-in function

Source: Internet
Author: User
Tags ord

#abs函数, Absolute


#all函数, the parameter passed in is a sequence, and only if all the elements in the list are true, then what is true?
#None, ' empty string, [] empty list, {} empty dictionary, 0 false


#any函数, the passed in parameter is also a sequence, so long as one element is true, the result is true


#bin, convert a decimal number to a binary number

#oct, convert a decimal into octal

#hex, convert a decimal to hexadecimal



#bool, view a Boolean value for a parameter

# ret = bool (0)
# Print (ret)
# # False
# ret = bool (None)
# Print (ret)
# # False
# ret = bool (1)
# Print (ret)
# # True


#bytes函数, Utf-8 encoding, a Chinese character is 3 bytes, GBK encoded, a Chinese character is 2 bytes, you can convert a string to a byte type
s = ' Zidane '
x = bytes (s,encoding= ' Utf-8 ')
Print (x)
# b ' \xe9\xbd\x90\xe8\xbe\xbe\xe5\x86\x85 '

x = bytes (s,encoding= ' GBK ')
Print (x)
# b ' \xc6\xeb\xb4\xef\xc4\xda '



#str函数, convert bytes to Strings

#callable, whether it can be executed, returns true if it can be executed, or false if it cannot

f = Lambda a:a-1
L = [n/A]

Print (callable (f))
Print (Callable (L))

# True
# False



#ord, convert a character to Ascil code, CHR is to convert a ascil code character

Print (Ord (' A '))
Print (Chr (65))

# 97
# A

#这里在介绍一个random的函数, a random number can be generated, which is useful when generating a verification code, via random
#函数产生随机的数字, and then convert the random number to the corresponding Ascil code by the CHR function
Import Random
ret = Random.randint (1,34)
Print (ret)



#dict, create the function's


#dir

#divmod, quotient and remainder

# ret = Divmod (7,3)
# Print (ret)

#enumerate, you can add a sequence to the output
Li = [' abc ', ' CDA ', ' afe ']
# for I in Li:
# Print (i)

# ABC
# CDA
# AFE



# for I,item in Enumerate (li,1):
# Print (I,item)

# 1 ABC
# 2 CDA
# 3 Afe

Def show ():
Print (' a ')
return [11,33,44]
Print (' B ')

ret = Show ()
Print (ret)


Def show ():
Print (' a ')
if 1 = = 2:
return [' A ', ' B ']
Print (' B ')
ret = Show ()

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.