Built-in functions and python built-in functions

Source: Internet
Author: User

Built-in functions and python built-in functions

'''Abs () dict () help () min () setattr () all () dir () hex () next () slice () any () divmod () id () object () sorted () ascii () enumerate () input () oct () staticmethod () bin () eval () int () open () str () bool () exec () isinstance () ord () sum () bytearray () filter () issubclass () pow () super () bytes () float () iter () print () tuple () callable () format () len () property () type () chr () frozenset () list () range () vars () classmethod () getattr () locals () repr () zip () compile () globals () map () reversed () _ import _ () complex () hasattr () max () round () delattr () hash () memoryview () set () ''' # absolute value print (abs (-199.23), 'abs ') # All elements in the input sequence are true (the elements in the sequence are 0, '', None, all false. dictionary, Judge key) returns true, otherwise false print (all (1, 2, 3, 4, 5), 'all ') # True is returned only when all elements in the input sequence are false. Otherwise, false print (any ([0, '', None]), any (1, 0, '', None), 'any') # returns the string a = ascii ([1, 2, 3, 4, 5]) of a printable object. print (type (ascii (a), 'ascii ') # Return a printable object string print (repr ('20170101'), 'repr ') # determining the logical value of an object print (bool (1), bool ([]), and 'bool ') # convert the sequence to a byte array, encode the string (UTF8: one Chinese Character = three bytes, gkb = two bytes) print (bytearray ([1, 2, 3, 4, 5]), bytearray ('zhang san', encoding = 'gb2312'), 'bytearray') # convert the sequence to a byte string, and encode the string (UTF8 Chinese Character = three bytes, gkb = two bytes) print (bytes ([1, 2, 3, 4, 5]), bytes ('zhang san', encoding = 'gb2312'), 'bytes ') # The returned result is true if the object can be executed. Otherwise, false fun1 = lambda x: x + 10 print (callable (fun1), callable ("1"), 'callable ') # convert ascii code into characters (less than 0x110000 or 1114112) print (chr (25106), 'chr ') # convert a single character to an ascii code print (ord ('I'), 'ord ') # class method # classmethod () # class method # staticmethod () # class method # super () # class method # isinstance () # class method # issubclass () # class method # iter () # class method # property () # class method # slice () # compile code # compile ('print (1) ') # print (complex (3.141592654), 'compute') in the plural form ') # object operations # delattr () # object operations # getattr () # object operations # hasattr () # object operations # setattr () # generate a dictionary class print (dict (k1 = '1'), 'dict ') # view all methods of the class. If it is null, view all current variable names print (dir (), 'dir') # view all the methods of the class. If it is null, view all the current variable names and values print (vars (list), 'vars') # quotient and remainder print (divmod (10, 3), 'divmod') # enumeration sequence, returns the repeated algebra and sequence elements. Parameter 1 is the sequence, parameter 2 is the iteration start value (0 by default) l1 = {'A ': 'a1', 'B': 'b1 ', 'C': 'c1', 'D': 'd1'} for I, m in enumerate (l1, 10 ): print (I, m, 'enumerate') # Calculate the string expression, and return the result print (eval ('1 + 2*5/10 '), 'eval') # Calculate the string expression, returns Noneprint (exec ('1 + 2*5/10 '), 'exec') # retrieves each element of the sequence and transmits it to the function (each time the function receives an element ), after the traveling operation, a new sequence is returned, and each element after the operation is added to def fun1 (x): if x> 4: x + = 5 x-+ 100 x * = 55 return x # lambda x: x + 5, you can also use the lambda function print (list (map (fun1, [1, 2, 3, 4, 5, 6, 7]), 'map') # filter, the element is passed into the function, return True according to the function body, and add it in the new sequence, false: do not add def fun2 (x): if x> 4: return True else: return Falseprint (list (filter (fun2, [1, 2, 3, 4, 5, 6, 7]), 'filter') # convert a numeric or numeric string to a floating point print (float ('1. 15164 '), 'float') # format String print (format ('3. 14% d % f % s' % (5, 1.15, '6') # convert to set a = set ([1, 2, 3]) print (, 'set') # freeze set B = frozenset (a) # B. add (6) # add and discardprint (B, 'frozenset') # display all global variables # print (globals (), 'globals ') # print (hash ('123'), 'hash') # view the help Document # print (help (list), 'help ') #10 to 16 hexadecimal print (hex (10), 'hex') #10 to 8 hexadecimal print (oct (10), 'oct ') #10 to binary print (bin (10), 'bin') # view the object memory address print (id (fun1), 'id ') # input content # print (input ("Enter content:"), 'input') # convert to an integer print (int ('123'), int (1234 ), 'int') # obtain the object length print (len ('sdfsdfdiruri '), 'len') # convert to list l1 = (1, 2, 4, 5, 6) print (list (l1), 'LIST') # display local variables # print (locals (), 'locals') # Take the maximum value print (max (1, 2, 3, 4,), 'max ') # obtain the minimum value print (min (1, 2, 3, 4,), 'Min ') # Return a memor vies object # print (memoryview () # open the file and return an object f = open ('e: \ Download \ Python \ coding \ old boy \ built-in function. py', 'R') print (f, 'open') f. close () # Power print (pow (3, 3), 'pow') # print ('print ') # generate a specified range iterator. Parameter 1 = start position, parameter 2 = end position, parameter 3 = interval (negative number is decreasing) for I in range (15, 10,-2): print (I, 'range ') # Reverse Sequence print (list (reversed ([1, 2, 3]), 'reversed ') # rounding, parameter 2 = reserved decimal places, the default value is 0 print (round (1.333, 2), 'round') # sort. You can use reverse = True to reverse print (sorted ([1, 5, 6, 2, 3, 4], reverse = True), 'sorted') # convert to string print (str (1), 'str ') # Calculate the sum ([10, 2, 3, 4, 5, 76]) of an integer sequence, 'sum') # convert it to the original print (tuple ([1, 2, 3]), 'tuple') # view the Object type print (type ('000000'), 'type') # Sort multiple sequences in order, merge into a new sequence a = (1, 2, 3,) B = ['A', 'B', 'C',] c = {'k1 ': 'k1 ', 'k2': 'k2', 'k3': 'k3 '} nzip = list (zip (a, B, c) # [(1, 'A'), (2, 'B'), (3, 'C')] print (nzip, 'zip ')

  

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.