Common python functions

Source: Internet
Author: User
1. mathematical correlation 1. absolute value: abs (-1) 2. maximum and minimum values: max ([, 3]) and min ([, 3]) 3. sequence length: len (abc), len ([, 3]), len (, 3) 4. modulo: divmod) 5...
1. mathematical correlation 1. absolute value: abs (-1) 2. maximum and minimum values: max ([, 3]) and min ([, 3]) 3. sequence length: len ('ABC'), len ([, 3]), len (, 3) 4. modulo: pmod) 5. multiplication: pow (3/46, 4) // 2 ** 1.0, floating point: round (1) // 2. function related 1. Can the function be called: callable (funcname). Note that the funcname variable must be defined. 2. type judgment: isinstance (x, list/int). 3. Comparison: cmp ('hello', 'Hello ') 4. fast generation sequence: (x) range ([start,] stop [, step]) 3. type conversion 1, int (x) 2, long (x) 3. float (x) 4, complex (x) // plural number 5, str (x) 6, list (x) 7, tuple (x) // tuples 8, hex (x) 9, oct (x) 10, chr (x) // returns the characters corresponding to x, such as chr (65) return 'A' 11, ord (x) // return the number of the ASC code corresponding to the character. for example, ord ('A') returns 65. string processing 1. uppercase letters: str. capitalize2, string replacement: str. replace3, string cutting: str. split 5. sequence processing functions 1. len: sequence length 2. max: maximum value in the sequence 3. min: minimum value 4. filter: filter sequence 6. parallel zip map reduce

Time type processing:

Time. time () returns the current timestamp, namely, 1394647431.90625 seconds. asctime () returns the ascii table format at that time, 'thu Mar 13 02:03:46 123' time. the string format of ctime () current time is 'thu Mar 13 02:04:59 123456' and the ascii code table is displayed in the same format as time. ctime (); time. ctime (time. time () you can specify a timestamp to convert it to the string format 'wed Mar 12 08:26:26 123' time. localtime () returns the internal time format struct_time format time of the current time zone. struct_time (maid = 2014, tm_mon = 3, tm_mday = 13, tm_hour = 2, tm_min = 8, tm_sec = 14, tm_wday = 3, tm_yday = 72, tm_is Dst = 0) time. localtime () [: 6] # (2014, 3, 13, 8, 15, 7, 3, 72) time. localtime () [0: 9] # (2014, 3, 13, 8, 15, 24, 3, 72, 0) time. gmtime () converts the timestamp into the struct_time structure of the UTC time zone (0 time zone), time. mktime () converts an internal time format to a timestamp, that is, 1394583457.0 time in seconds. mktime (time. localtime (time. time (), such as 1394583457.0time.strftime ("% Y-% m-% d", time. localtime (time. time () can be used to convert the internal time structure into the specified string format '2017-3-12 'time. strftime ("% Y-% m-% d % H: % M: % S", time. lo Caltime () such as '2017-03-13 01:54:27 'time. strftime ("% a % B % d % H: % M: % S % Y", time. localtime (), such as 'thu Mar 13 01:55:05 123' time. strptime () converts the string format time to the internal time format time. strptime ("Sat Mar 28 22:24:25 2009", "% a % B % d % H: % M: % S % Y") returns a struct_time structure time. struct_time (maid = 2009, tm_mon = 3, tm_mday = 28, tm_hour = 22, tm_min = 24, tm_sec = 25, tm_wday = 5, tm_yday = 87, tm_isdst =-1) a = "Sat Mar 28 22:24:24 2009" this is to turn the character into stru After the ct_time internal structure, use time. mktime () to generate a timestamp, that is, to generate a string. B = time. mktime (time. strptime (a, "% a % B % d % H: % M: % S % Y "))

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.