Python 官方文档

Resource

Related

String

String Methods

  • capitalize()
  • center(width[, fillchar])
  • count(sub[, start[, end]])
  • decode
  • encode([encoding[, errors]])
  • endswith(suffix[, start[, end]])
  • expandtabs([tabsize])
  • find(sub[, start[, end]])
  • format(*args, **kwargs)
  • index(sub[, start[, end]])
  • isalnum()
  • isalpha()
  • isdecimal()
  • isdigit()
  • islower()
  • isnumeric()
  • isspace()
  • istitle()
  • isupper()
  • join(iterable)
  • ljust(width[, fillchar])
  • lower()
  • lstrip([chars])
  • partition(sep)
  • replace(old, new[, count])
  • rfind(sub[, start[, end]])
  • rindex(sub[, start[, end]])
  • rjust(width[, fillchar])
  • rpartition(sep)
  • rsplit([sep[, maxsplit]])
  • rstrip([chars])
  • split([sep[, maxsplit]])
  • splitlines([keepends])
  • startswith(prefix[, start[, end]])
  • strip([chars])
  • swapcase
  • title()
  • translate(table[, deletechars])
  • upper()
  • zfill(width)

File

Methods

  • close()
  • fileno()
  • flush()
  • isatty()
  • next()
  • read([size])
  • readline([size])
  • readlines([sizehint])
  • seek(offset[, whence])
  • tell()
  • truncate([size])
  • write(str)
  • writelines(sequence)
  • xreadlines()

Attributes

  • closed
  • encoding
  • errors
  • mode
  • name
  • newlines
  • softspace

Set & Mapping

Set Types

Mapping Types

  • key not in d
  • del d[key]
  • d[key]
  • len(d)
  • key in d
  • d[key] = value
  • fromkeys(seq[, value])
  • get(key[, default])
  • has_key(key)
  • items()
  • iteritems()
  • iterkeys()
  • itervalues()
  • keys()
  • pop(key[, default])
  • popitem()
  • setdefault(key[, default])
  • update([other])
  • values

Date Time

Date Object

  • __str__()
  • ctime()
  • isocalendar()()
  • isoformat()
  • isoweekday()()
  • replace((year, month, day))
  • strftime()
  • timetuple()
  • toordinal()
  • weekday()()

Datetime Object

  • astimezone(tz)
  • date()
  • dst()
  • isocalendar()
  • isoweekday()
  • replace([year[, month[, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]]]]])
  • time()
  • timetz()
  • tzname()
  • utcoffset()
  • utctimetuple()
  • weekday()

Time Object

Array

Array Methods

  • append(x)
  • buffer_info()
  • byteswap()
  • count(x)
  • extend(iterable)
  • fromfile(f,n)
  • fromlist(list)
  • fromstring(s)
  • fromunicode(s)
  • index(x)
  • insert(i,x)
  • pop([i])
  • remove(x)
  • reverse()
  • tofile(f)
  • tolist()
  • tostring()
  • tounicode()

Math

Number Theoretic

  • ceil(x)
  • copysign(x,y)
  • fabs(x)
  • factorial(x)
  • floor(x)
  • fmod(x,y)
  • frexp(x)
  • fsum(iterable)
  • isinf(x)
  • isnan(x)
  • ldexp(x,i)
  • modf()
  • trunc()

Power and Logarithmic

  • exp(x)
  • log(x[,base])
  • log10(x)
  • log1p(x)
  • pow(x,y)
  • sqrt(x)

Trigonometric Functions

  • acos(x)
  • asin(x)
  • atan(x)
  • atan2(y,x)
  • cos(x)
  • hypot(x,y)
  • sin(x)
  • tan(x)

Angular Conversion

  • degrees(x)
  • radians(x)

Hyperbolic Functions

  • acosh(x)
  • asinh(x)
  • atanh(x)
  • cosh(x)
  • sinh(x)
  • tanh(x)

Constants

  • math.e
  • The mathematical constant e = 2.718281..., to available precision.
  • math.pi
  • The mathematical constant π = 3.141592..., to available precision.

Random

Functions

Sys

Sys Variables

OS

os Variables

String Formatting

Formatting Operations

  • '%'
  • No argument is converted, results in a '%' character in the result.
  • 'c'
  • Single character (accepts integer or single character string).
  • 'd'
  • Signed integer decimal.
  • 'e'
  • Floating point exponential format (lowercase).
  • 'f'
  • Floating point decimal format.
  • 'g'
  • Floating point format. Uses lowercase exponential format if exponent is less than -4 or not less than precision, decimal format otherwise.
  • 'i'
  • Signed integer decimal.
  • 'o'
  • Signed octal value.
  • 'r'
  • String (converts any Python object using repr().
  • 's'
  • String (converts any Python object using str()
  • 'd'.">'u'
  • Obsolete type – it is identical to 'd'.
  • 'x'
  • Signed hexadecimal (lowercase).

Date Formatting

Date Formatting

  • %%
  • A literal "%" character (%)
  • %a
  • Abbreviated weekday (Sun)
  • %b
  • Abbreviated month name (Jan)
  • %c
  • Date and time
  • %d
  • Day (leading zeros) (01 to 31)
  • %H
  • 24 hour (leading zeros) (00 to 23)
  • %I
  • 12 hour (leading zeros) (01 to 12)
  • %j
  • Day of year (001 to 366)
  • %m
  • Month (01 to 12)
  • %p
  • AM or PM
  • %S
  • Second (00 to 61?)
  • %U
  • Week number1 (00 to 53)
  • %w
  • Weekday2 (0 to 6)
  • %x
  • Date
  • %y
  • Year without century (00 to 99)
  • %Z
  • Time zone (GMT)