Python common functions

Source: Internet
Author: User
Tags ord
   I. Mathematics-related 1, absolute value: ABS (-1) 2, Maximum minimum: max ([+]), MIN ([]) 3, sequence length: Len (' abc '), Len ([+]), Len ((+)) 4, modulo: Divmod (5,2 )//(2,1) 5, Power: Pow (2,3,4)//2**3/46, floating point: Round (1)//1.0 Two, function-related 1, function can be called: callable (funcname), note that the funcname variable to be defined 2, Type judgment: Isinstance (X,list/int) 3, Comparison: CMP (' hello ', ' Hello ') 4, Fast generation sequence: (x) range ([Start,] stop[, step]) three, type conversion 1, int (x) 2, long (x) 3, float (x) 4, complex (x)//complex 5, str (x) 6, List (x) 7, tuple (x)//tuple 8, Hex (x) 9, Oct (x) 10, Chr (x)//return x corresponding character, such as Chr (65) return ' A ' 11, ord (x)//return the character corresponding to the ASC code number, such as Ord (' A ') return 654, string processing 1, the first letter uppercase: Str.capitalize2, string substitution: Str.replace3, string cutting: Str.split Five, Sequence processing function 1, len: sequence length 2, max: Maximum value in series 3, min: Minimum 4, filter: Filter sequence VI, parallel  zip  map   reduce

Time Type processing:

Time.time () returns the current timestamp that is, the number of seconds 1394647431.90625 time.asctime () returns the ASCII-style situation of the time, ' Thu Mar 02:03:46 ' Time.ctime () The string form of the current time ' Thu Mar 13 02:04:59 2014 ' and ASCII table explicit form time.ctime (); Time.ctime (Time.time ()) can specify a time stamp to turn to string form ' Wed Mar 12 08:26 : "Time.localtime () returns the internal time format of the current TimeZone struct_time format time.struct_time (tm_year=2014, tm_mon=3, tm_mday=13, tm_hour= 2, Tm_min=8, tm_sec=14, tm_wday=3, tm_yday=72, tm_isdst=0) Time.localtime () [: 6] # (8, 3, 7, 3,) Time.loca Ltime () [0:9] # (3, 8, 3, 0) Time.gmtime () transforms the timestamp into the struct_time structure of the UTC time zone (0 o'clock Zone), and Time.mktime () converts the internal time format to Timestamp, that is, the number of seconds 1394583457.0 time.mktime (Time.localtime (Time.time ())) such as 1394583457.0time.strftime ("%y-%m-%d", Time.localtime (Time.time ())) has transformed the internal time structure into our human-readable specified string format ' 2014-3-12 ' Time.strftime ("%y-%m-%d%h:%m:%s", Time.localtime ()) such as ' 2014-03-13 01:54:27 ' time.strftime ("%a%b%d%h:%m:%s%Y", Time.localtime ()) such as ' Thu Mar 13 01:55:05 2014 ' Time.strptime () turns the time of the string format into the internal timing format time.strptime ("Sat Mar 22:24:25", "%a%B%d%h:%m:%s%Y ") returns a Struct_time structure time time.struct_time (tm_year=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 28 22:24:24 2009" This is to turn the character into a struct_time internal structure and then use the Time.mktime () to generate the timestamp , the string is generated. b = Time.mktime (Time.strptime (A, "%a%b%d%h:%m:%s%Y"))
  • 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.