Python's built-in functions

Source: Internet
Author: User
Tags decimal to binary ord

1, first look at a list of built-in functions:

1.abs () function This function is used to return the absolute value of a variable

1>>> a=-32>>> b=ABS (a)3>>>Print(type (b), b)4<class 'int'> 35>>> c=-6+7j6>>> d=ABS (c)7>>>Print(Type (d), D)#here is the absolute value of a complex number, which returns its modulus? 8<class 'float'> 9.2195444572928879>>> c=7-6jTen>>> d=ABS (c) One>>>Print(d) A9.219544457292887

2, the All () function, you can pass a parameter to the parentheses, this parameter must be iterative, if the inside of the iterator object inside the element value is True--true, then the entire all () function returns True, otherwise as long as there is a value of false--false, then return false

1>>> a=[1,2,3,4]#the values inside are true.2>>> b=All (a)3>>>Print(b)4True#returns True5>>> c=[0,123,"", None]#the 0 inside, "" and none of them are false .6>>> d=All (c)7>>>Print(d)8False#returns false

3, any () function, almost the opposite of the All () function, it is as long as the parentheses of the elements of an iterative object as long as one is true, then return true, all false, to return false

1>>> c=[0,123,"", None]2>>> d=All (c)3>>>Print(d)4 False5 #when the element inside the list C is false, all () returns false6>>> e=Any (c)7>>>Print(e)8True#Here you can see that the any () function returns True9>>> F=[0,"", None]Ten>>> e=Any (f) One>>>Print(e) A False - #If you can see that the elements inside an iterative object F are all false, return false

4, the basestring () function, which is the parent of a string and Unicode universal code, can be used to determine whether an object is a string or unicode,isinstance (obj,basestring) equivalent to isinstance (obj, str , Unicode), which is less used

5, about the conversion of some functions, bin () convert decimal to Binary, Oct () to convert decimal to octal number, Hex () Convert decimal number to 16 binary number

1>>> a=52>>> B=bin (a)#converts a to a binary number, and the binary number starts with 0b3>>>Print(b)4 0b1015>>> C=oct (a)#convert A to octal number, binary number starts with 06>>>Print(c)7 0o58>>> D=hex (a)#converts a to a number of 16 binary, the number of binary starts with 0x9>>>Print(d)Ten0x5

6, BOOL (), return a bool value, judge a number is really false

7, Chr (), UNICHR () and Ord () function,

1>>>Help (Chr ())2 4Chr (i)character5 6 7Return a string of one character with ordinal i; 0 <= I < 256.8 9 Ten #The parameter is an integer of 0-256, and the return value is the ASCII character corresponding to the current integer. Parameters can be either 10 or 16 in the form of a binary One  A #the following are hexadecimal: ->>>PrintChr (0x30), Chr (0x31), Chr (0x61) -0 1a the   - #The following are the decimal: ->>>PrintCHR, CHR, Chr (97) -0 1a +  -   +>>>Help (UNICHR ()) A  at  -UNICHR (i)Unicode character -Return a Unicode string of one character with ordinal i; 0 <= i <= 0x10ffff. -  - #The UNICHR () and Chr () functions are basically the same, except that they return Unicode characters -  in>>>Help (Ord ()) -Ord (c)integer toReturn the integer ordinal of a one-character string. +  -  the #The parameter is an ASCII character, and the return value is the corresponding decimal integer *  $>>>PrintOrd'a'), Ord ('0'), Ord ('1')Panax Notoginseng97 48 49 -  the>>>Print "%x %x"% (Ord ('a'), Ord ('0'), Ord ('1')) +61 30 31 A>>>Print "% #x% #x% #x"% (Ord ('a'), Ord ('0'), Ord ('1')) the0x61 0x30 0x31 +  - #by combining Chr () and Ord (), we can convert a string to a related operation, such as a string str1, into another string str2, so str2[i] = str1[i]-I $  $&GT;&GT;&GT;STR1 ="eb;3ej8h" ->>> forIinchRange (0, Len (str1)): -...PrintChr ((Ord (str1[i))-i)), the ...  -E a 9 0 A E 2 a

8, int (), str (), list (), tuple (), Dict (), set () function, these are factory functions,

1 #Int () is the creation of an integer object, or the transformation of an object into an integral type2 #str () is to create a string object, or to convert an object to a string type3 #List () is the creation of a listing object, or the conversion of an object to a list type4 #tuple () is the creation of a tuple object, or the transformation of an object into a tuple type5 #Dict () is to create a Dictionary object6 #set () is to create a collection object, or to turn an object into a collection7>>> a="123"8>>> B=int (a)#Convert string A to Integer b9>>>bTen123 One>>> c=tuple (a) A #Converts the string A to Narimoto group C and outputs the characters inside the string as elements in the tuple C ->>>C -('1','2','3') the>>> d=List (a) - #Convert string A to list D, and output the characters inside the string as the elements in the list D ->>>D -['1','2','3'] +>>> f=dict ()#Create an empty dictionary ->>>Print(Type (f)) +<class 'Dict'>

>>> G=set (a)
#把字符串a转变成集合g and output the characters inside the string as elements inside the set G

>>> Print (g)
{' 3 ', ' 2 ', ' 1 '}

9.

Python's built-in functions

Related Article

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.