On Python factory functions and built-in functions

Source: Internet
Author: User
Tags ord

the so-called factory function means that these built-in functions are class objects, and when you call them, you actually create a class instance.  Factory Function:int (), long (), float (), complex (), BOOL ()str (), Unicode (), basestring ()List (), tuple (): Generate lists or tuplestype (): View typedict (): Generate a dictionaryset (): Producing a mutable setFrozenset (): Creating Immutable Collectionsobject ()Classmethod (): Declaring a class methodStaticmethod (): Declares a static methodsuper (): Refers to the parent class of this classProperty ()file ()  numeric type built-in functions:function Built-in functions:built-in functions applied to all numeric types abs (), coerce (), Divmod (), Pow (), and Round (),Built -in functions for integers only: This function is divided into two categories:One class for binary conversions: Oct () octal conversion, Hex () 16 binary conversion. >>> Hex (255)' 0xFF '>>> Oct (255)' 0377 '>>> Oct (23094823l)' 0130063047L '>>> Oct (65535*2)' 0377776 'A class for ASCII conversions:. Each character corresponds to a unique integer (0-255). chr (num) converts the number of ASCII values into ASCII characters, which can only be 0<= num <= 255. Ord accepts an ASCII or Unicode character (a string of length 1) and returns the corresponding ASCII or Unicode value. UNICHR (NUM) accepts Unicode code values and returns their corresponding Unicode characters. The range of code values accepted depends on whether your Python is built on ucs‐2 or ucs‐4.  >>> Ord (' a ') the>>> Ord (' A ') $>>> Ord (' 0 ') -   string built-in functionsMethod Descriptionstring.capitalize () capitalizes the first character of a string string.center (width) returns the center of the original string and fills the new string with a space of length width string.count (str, Beg=0,end=len (String)) returns the number of occurrences of STR in a string, if beg or end specifies the number of occurrences of STR in the specified range String.decode (encoding= ' UTF-8 ', errors= ' strict ') decodes a string in encoding specified encoding format, and if an error defaults to a ValueError exception, unless errors The designation is ' ignore ' or ' replace ' String.encode (encoding= ' UTF-8 ', errors= ' strict ') encodes a string in encoding specified encoding format, and if an error defaults to a ValueError exception, unless errors The designation is ' ignore ' or ' replace ' string.endswith (obj, Beg=0,end=len (string)) checks whether the string ends with obj, if beg or end specifies whether the specified range is terminated with obj, and if yes, returns true, otherwise false . string.expandtabs (tabsize=8) Turns the tab symbol in string strings to a space, and the default number of spaces Tabsize is 8. string.find (str, Beg=0,end=len (string)) detects whether STR is contained in a string, and if beg and end specify a range, the check is contained within the specified range. Returns the starting index value if it is returned-1string.index (str, Beg=0,end=len (String)) is the same as the Find () method, except that STR does not report an exception if it is not in a string. String.isalnum () returns True if the string has at least one character and all characters are letters or numbers, otherwise false String.isalpha () returns True if the string has at least one character and all characters are letters, otherwise false String.isdecimal () returns True if the string contains only a decimal number, otherwise false is returned. String.isdigit () returns True if the string contains only a number, otherwise false. String.islower () returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are lowercase, otherwise false String.isnumeric () returns True if the string contains only numeric characters, otherwise false String.isspace () returns True if the string contains only spaces, otherwise false. String.istitle () returns True if String is heading (see Title ()), otherwise false String.isupper () returns True if the string contains at least one case-sensitive character, and all of these (case-sensitive) characters are uppercase, otherwise false string.join (seq) Merges (concatenates) merges all elements of the SEQ (string representation) into a new string as a string delimiter string.ljust (width) returns the left alignment of an original string and fills the new string with a space of length width String.Lower () converts all uppercase characters in a string to lowercase. String.lstrip () truncates the left space of a string string.partition (str) is a bit like the combination of find () and split (), which separates string strings into a 3-element tuple from the first position in STR (STRING_PRE_STR,STR , string_post_str), String_pre_str ==string If the string does not contain str. string.replace (str1, Str2,num=string.count (STR1)) replaces str1 in string with STR2, and if NUM is specified, the substitution is not more than num times. string.rfind (str, Beg=0,end=len (string)) is similar to the Find () function, but looks up from the right. string.rindex (str, Beg=0,end=len (string)) is similar to index (), but starts from the right. string.rjust (width) returns the right alignment of the original string and fills the new string with a space of length width string.rpartition (str) is similar to the partition () function, but looks up from the right. String.rstrip () deletes a space at the end of a string string. String.Split (str= "", Num=string.count (str)) slices a string with the Str delimiter, and if NUM has a specified value, only the NUM substring is delimited string.splitlines (num=string.count (' \ n ')) is separated by rows, returns a list containing the rows as elements, and if num specifies only a slice of num rows. string.startswith (obj, Beg=0,end=len (string)) checks whether the string starts with obj, returns True, or false. If beg and end specify a value, the check is within the specified range String.strip ([obj]) executes Lstrip () and Rstrip () on string string.swapcase () flips the casing in a string String.title () returns a string that is "heading", meaning that all words start with uppercase and the remaining letters are lowercase (see istitle ()) string.translate (str, del= "") converts string characters according to the table given by STR (contains 256 characters), and the characters to be filtered out into the del parameter string.upper () converts lowercase letters in string to uppercaseString.zfill (width) returns a string of length width, the original string is right-aligned, the front padding 0 list type built-in functions:List Method Operationlist.append (obj) adds an object to the list objlist.count (obj) returns the number of times an object obj appears in the listlist.extend (seq) a adds the contents of the sequence SEQ to the listlist.index (obj, i=0,J=len (list) returns the K value of the list = = obj, and the range of K is i<=kthrows an ValueError exception.List.insert (index, OBJ) inserts the object obj at the index position.List.pop (Index=-1) a deletes and returns the object at the specified position, which is the last object by defaultlist.remove (obj) removes an object from the list objlist.reverse () flip list in placeList.sort (func=none,key=none,reverse=false) b sorts the members in the list in the specified way, if the Func and key parameters are specified,The individual elements are compared in the specified manner if the reverse flag is set toTrue, the list is ordered in reverse order. tuples have no built-in functions.  mapping type built-in functions:CMP (): Comparison of dictionaries, first comparing lengths, in comparing keys, in comparing values of dictionariesLen ():. Call Len () to the dictionary, which returns the number of all elements (key-value pairs):Hash (): The built-in function hash () itself is not a method designed for a dictionary, but it can determine whether an object can do a dictionary key. Pass an object as a parameter to the hash (), returns the hash value of this object. Only this object is hashed and can be used as a dictionary key (the return value of the function is an integer and does not produce an error or exception).

(turn) on Python factory functions and built-in functions

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.