python输入三角形三边处理成三个实数_Python之路:(三)数据处理
一、進制
二進制,01
八進制,01234567
十進制,0123456789
十六進制,0123456789ABCDEF
二、整數(int)
如: 18、73、84
每一個整數都具備如下功能:
int
classint(object):"""int(x=0) -> integer
int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4"""
def bit_length(self): #real signature unknown; restored from __doc__
"""int.bit_length() -> int
Number of bits necessary to represent self in binary.
>>> bin(37)
'0b100101'
>>> (37).bit_length()
6"""
return0def conjugate(self, *args, **kwargs): #real signature unknown
"""Returns self, the complex conjugate of any int."""
pass@classmethod#known case
def from_bytes(cls, bytes, byteorder, *args, **kwargs): #real signature unknown; NOTE: unreliably restored from __doc__
"""int.from_bytes(bytes, byteorder, *, signed=False) -> int
Return the integer represented by the given array of bytes.
The bytes argument must be a bytes-like object (e.g. bytes or bytearray).
The byteorder argument determines the byte order used to represent the
integer. If byteorder is 'big', the most significant byte is at the
beginning of the byte array. If byteorder is 'little', the most
significant byte is at the end of the byte array. To request the native
byte order of the host system, use `sys.byteorder' as the byte order value.
The signed keyword-only argument indicates whether two's complement is
used to represent the integer."""
pass
def to_bytes(self, length, byteorder, *args, **kwargs): #real signature unknown; NOTE: unreliably restored from __doc__
"""int.to_bytes(length, byteorder, *, signed=False) -> bytes
Return an array of bytes representing an integer.
The integer is represented using length bytes. An OverflowError is
raised if the integer is not representable with the given number of
bytes.
The byteorder argument determines the byte order used to represent the
integer. If byteorder is 'big', the most significant byte is at the
beginning of the byte array. If byteorder is 'little', the most
significant byte is at the end of the byte array. To request the native
byte order of the host system, use `sys.byteorder' as the byte order value.
The signed keyword-only argument determines whether two's complement is
used to represent the integer. If signed is False and a negative integer
is given, an OverflowError is raised."""
pass
def __abs__(self, *args, **kwargs): #real signature unknown
"""abs(self)"""
pass
def __add__(self, *args, **kwargs): #real signature unknown
"""Return self+value."""
pass
def __and__(self, *args, **kwargs): #real signature unknown
"""Return self&value."""
pass
def __bool__(self, *args, **kwargs): #real signature unknown
"""self != 0"""
pass
def __ceil__(self, *args, **kwargs): #real signature unknown
"""Ceiling of an Integral returns itself."""
pass
def __divmod__(self, *args, **kwargs): #real signature unknown
"""Return divmod(self, value)."""
pass
def __eq__(self, *args, **kwargs): #real signature unknown
"""Return self==value."""
pass
def __float__(self, *args, **kwargs): #real signature unknown
"""float(self)"""
pass
def __floordiv__(self, *args, **kwargs): #real signature unknown
"""Return self//value."""
pass
def __floor__(self, *args, **kwargs): #real signature unknown
"""Flooring an Integral returns itself."""
pass
def __format__(self, *args, **kwargs): #real signature unknown
pass
def __getattribute__(self, *args, **kwargs): #real signature unknown
"""Return getattr(self, name)."""
pass
def __getnewargs__(self, *args, **kwargs): #real signature unknown
pass
def __ge__(self, *args, **kwargs): #real signature unknown
"""Return self>=value."""
pass
def __gt__(self, *args, **kwargs): #real signature unknown
"""Return self>value."""
pass
def __hash__(self, *args, **kwargs): #real signature unknown
"""Return hash(self)."""
pass
def __index__(self, *args, **kwargs): #real signature unknown
"""Return self converted to an integer, if self is suitable for use as an index into a list."""
pass
def __init__(self, x, base=10): #known special case of int.__init__
"""int(x=0) -> integer
int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4
# (copied from class doc)"""
pass
def __int__(self, *args, **kwargs): #real signature unknown
"""int(self)"""
pass
def __invert__(self, *args, **kwargs): #real signature unknown
"""~self"""
pass
def __le__(self, *args, **kwargs): #real signature unknown
"""Return self<=value."""
pass
def __lshift__(self, *args, **kwargs): #real signature unknown
"""Return self<
pass
def __lt__(self, *args, **kwargs): #real signature unknown
"""Return self
pass
def __mod__(self, *args, **kwargs): #real signature unknown
"""Return self%value."""
pass
def __mul__(self, *args, **kwargs): #real signature unknown
"""Return self*value."""
pass
def __neg__(self, *args, **kwargs): #real signature unknown
"""-self"""
pass@staticmethod#known case of __new__
def __new__(*args, **kwargs): #real signature unknown
"""Create and return a new object. See help(type) for accurate signature."""
pass
def __ne__(self, *args, **kwargs): #real signature unknown
"""Return self!=value."""
pass
def __or__(self, *args, **kwargs): #real signature unknown
"""Return self|value."""
pass
def __pos__(self, *args, **kwargs): #real signature unknown
"""+self"""
pass
def __pow__(self, *args, **kwargs): #real signature unknown
"""Return pow(self, value, mod)."""
pass
def __radd__(self, *args, **kwargs): #real signature unknown
"""Return value+self."""
pass
def __rand__(self, *args, **kwargs): #real signature unknown
"""Return value&self."""
pass
def __rdivmod__(self, *args, **kwargs): #real signature unknown
"""Return divmod(value, self)."""
pass
def __repr__(self, *args, **kwargs): #real signature unknown
"""Return repr(self)."""
pass
def __rfloordiv__(self, *args, **kwargs): #real signature unknown
"""Return value//self."""
pass
def __rlshift__(self, *args, **kwargs): #real signature unknown
"""Return value<
pass
def __rmod__(self, *args, **kwargs): #real signature unknown
"""Return value%self."""
pass
def __rmul__(self, *args, **kwargs): #real signature unknown
"""Return value*self."""
pass
def __ror__(self, *args, **kwargs): #real signature unknown
"""Return value|self."""
pass
def __round__(self, *args, **kwargs): #real signature unknown
"""Rounding an Integral returns itself.
Rounding with an ndigits argument also returns an integer."""
pass
def __rpow__(self, *args, **kwargs): #real signature unknown
"""Return pow(value, self, mod)."""
pass
def __rrshift__(self, *args, **kwargs): #real signature unknown
"""Return value>>self."""
pass
def __rshift__(self, *args, **kwargs): #real signature unknown
"""Return self>>value."""
pass
def __rsub__(self, *args, **kwargs): #real signature unknown
"""Return value-self."""
pass
def __rtruediv__(self, *args, **kwargs): #real signature unknown
"""Return value/self."""
pass
def __rxor__(self, *args, **kwargs): #real signature unknown
"""Return value^self."""
pass
def __sizeof__(self, *args, **kwargs): #real signature unknown
"""Returns size in memory, in bytes"""
pass
def __str__(self, *args, **kwargs): #real signature unknown
"""Return str(self)."""
pass
def __sub__(self, *args, **kwargs): #real signature unknown
"""Return self-value."""
pass
def __truediv__(self, *args, **kwargs): #real signature unknown
"""Return self/value."""
pass
def __trunc__(self, *args, **kwargs): #real signature unknown
"""Truncating an Integral returns itself."""
pass
def __xor__(self, *args, **kwargs): #real signature unknown
"""Return self^value."""
passdenominator= property(lambda self: object(), lambda self, v: None, lambda self: None) #default
"""the denominator of a rational number in lowest terms"""imag= property(lambda self: object(), lambda self, v: None, lambda self: None) #default
"""the imaginary part of a complex number"""numerator= property(lambda self: object(), lambda self, v: None, lambda self: None) #default
"""the numerator of a rational number in lowest terms"""real= property(lambda self: object(), lambda self, v: None, lambda self: None) #default
"""the real part of a complex number"""
View Code
三、浮點型(float)
如:3.14、2.88
每個浮點型都具備如下功能:
float
classfloat(object):"""float(x) -> floating point number
Convert a string or number to a floating point number, if possible."""
def as_integer_ratio(self): #real signature unknown; restored from __doc__
"""float.as_integer_ratio() -> (int, int)
Return a pair of integers, whose ratio is exactly equal to the original
float and with a positive denominator.
Raise OverflowError on infinities and a ValueError on NaNs.
>>> (10.0).as_integer_ratio()
(10, 1)
>>> (0.0).as_integer_ratio()
(0, 1)
>>> (-.25).as_integer_ratio()
(-1, 4)"""
pass
def conjugate(self, *args, **kwargs): #real signature unknown
"""Return self, the complex conjugate of any float."""
pass
def fromhex(self, string): #real signature unknown; restored from __doc__
"""float.fromhex(string) -> float
Create a floating-point number from a hexadecimal string.
>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324"""
return 0.0
def hex(self): #real signature unknown; restored from __doc__
"""float.hex() -> string
Return a hexadecimal representation of a floating-point number.
>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'"""
return ""
def is_integer(self, *args, **kwargs): #real signature unknown
"""Return True if the float is an integer."""
pass
def __abs__(self, *args, **kwargs): #real signature unknown
"""abs(self)"""
pass
def __add__(self, *args, **kwargs): #real signature unknown
"""Return self+value."""
pass
def __bool__(self, *args, **kwargs): #real signature unknown
"""self != 0"""
pass
def __divmod__(self, *args, **kwargs): #real signature unknown
"""Return divmod(self, value)."""
pass
def __eq__(self, *args, **kwargs): #real signature unknown
"""Return self==value."""
pass
def __float__(self, *args, **kwargs): #real signature unknown
"""float(self)"""
pass
def __floordiv__(self, *args, **kwargs): #real signature unknown
"""Return self//value."""
pass
def __format__(self, format_spec): #real signature unknown; restored from __doc__
"""float.__format__(format_spec) -> string
Formats the float according to format_spec."""
return ""
def __getattribute__(self, *args, **kwargs): #real signature unknown
"""Return getattr(self, name)."""
pass
def __getformat__(self, typestr): #real signature unknown; restored from __doc__
"""float.__getformat__(typestr) -> string
You probably don't want to use this function. It exists mainly to be
used in Python's test suite.
typestr must be 'double' or 'float'. This function returns whichever of
'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the
format of floating point numbers used by the C type named by typestr."""
return ""
def __getnewargs__(self, *args, **kwargs): #real signature unknown
pass
def __ge__(self, *args, **kwargs): #real signature unknown
"""Return self>=value."""
pass
def __gt__(self, *args, **kwargs): #real signature unknown
"""Return self>value."""
pass
def __hash__(self, *args, **kwargs): #real signature unknown
"""Return hash(self)."""
pass
def __init__(self, x): #real signature unknown; restored from __doc__
pass
def __int__(self, *args, **kwargs): #real signature unknown
"""int(self)"""
pass
def __le__(self, *args, **kwargs): #real signature unknown
"""Return self<=value."""
pass
def __lt__(self, *args, **kwargs): #real signature unknown
"""Return self
pass
def __mod__(self, *args, **kwargs): #real signature unknown
"""Return self%value."""
pass
def __mul__(self, *args, **kwargs): #real signature unknown
"""Return self*value."""
pass
def __neg__(self, *args, **kwargs): #real signature unknown
"""-self"""
pass@staticmethod#known case of __new__
def __new__(*args, **kwargs): #real signature unknown
"""Create and return a new object. See help(type) for accurate signature."""
pass
def __ne__(self, *args, **kwargs): #real signature unknown
"""Return self!=value."""
pass
def __pos__(self, *args, **kwargs): #real signature unknown
"""+self"""
pass
def __pow__(self, *args, **kwargs): #real signature unknown
"""Return pow(self, value, mod)."""
pass
def __radd__(self, *args, **kwargs): #real signature unknown
"""Return value+self."""
pass
def __rdivmod__(self, *args, **kwargs): #real signature unknown
"""Return divmod(value, self)."""
pass
def __repr__(self, *args, **kwargs): #real signature unknown
"""Return repr(self)."""
pass
def __rfloordiv__(self, *args, **kwargs): #real signature unknown
"""Return value//self."""
pass
def __rmod__(self, *args, **kwargs): #real signature unknown
"""Return value%self."""
pass
def __rmul__(self, *args, **kwargs): #real signature unknown
"""Return value*self."""
pass
def __round__(self, *args, **kwargs): #real signature unknown
"""Return the Integral closest to x, rounding half toward even.
When an argument is passed, work like built-in round(x, ndigits)."""
pass
def __rpow__(self, *args, **kwargs): #real signature unknown
"""Return pow(value, self, mod)."""
pass
def __rsub__(self, *args, **kwargs): #real signature unknown
"""Return value-self."""
pass
def __rtruediv__(self, *args, **kwargs): #real signature unknown
"""Return value/self."""
pass
def __setformat__(self, typestr, fmt): #real signature unknown; restored from __doc__
"""float.__setformat__(typestr, fmt) -> None
You probably don't want to use this function. It exists mainly to be
used in Python's test suite.
typestr must be 'double' or 'float'. fmt must be one of 'unknown',
'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be
one of the latter two if it appears to match the underlying C reality.
Override the automatic determination of C-level floating point type.
This affects how floats are converted to and from binary strings."""
pass
def __str__(self, *args, **kwargs): #real signature unknown
"""Return str(self)."""
pass
def __sub__(self, *args, **kwargs): #real signature unknown
"""Return self-value."""
pass
def __truediv__(self, *args, **kwargs): #real signature unknown
"""Return self/value."""
pass
def __trunc__(self, *args, **kwargs): #real signature unknown
"""Return the Integral closest to x between 0 and x."""
passimag= property(lambda self: object(), lambda self, v: None, lambda self: None) #default
"""the imaginary part of a complex number"""real= property(lambda self: object(), lambda self, v: None, lambda self: None) #default
"""the real part of a complex number"""
View Code
一、字符串(string)
python字符串--一個有序的字符的集合,用來存儲和表現給予文本的信息。
str
classstr(object):"""str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'."""
def capitalize(self): #real signature unknown; restored from __doc__
"""S.capitalize() -> str
Return a capitalized version of S, i.e. make the first character
have upper case and the rest lower case."""
return ""
def casefold(self): #real signature unknown; restored from __doc__
"""S.casefold() -> str
Return a version of S suitable for caseless comparisons."""
return ""
def center(self, width, fillchar=None): #real signature unknown; restored from __doc__
"""S.center(width[, fillchar]) -> str
Return S centered in a string of length width. Padding is
done using the specified fill character (default is a space)"""
return ""
def count(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""S.count(sub[, start[, end]]) -> int
Return the number of non-overlapping occurrences of substring sub in
string S[start:end]. Optional arguments start and end are
interpreted as in slice notation."""
return0def encode(self, encoding='utf-8', errors='strict'): #real signature unknown; restored from __doc__
"""S.encode(encoding='utf-8', errors='strict') -> bytes
Encode S using the codec registered for encoding. Default encoding
is 'utf-8'. errors may be given to set a different error
handling scheme. Default is 'strict' meaning that encoding errors raise
a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and
'xmlcharrefreplace' as well as any other name registered with
codecs.register_error that can handle UnicodeEncodeErrors."""
return b""
def endswith(self, suffix, start=None, end=None): #real signature unknown; restored from __doc__
"""S.endswith(suffix[, start[, end]]) -> bool
Return True if S ends with the specified suffix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
suffix can also be a tuple of strings to try."""
returnFalsedef expandtabs(self, tabsize=8): #real signature unknown; restored from __doc__
"""S.expandtabs(tabsize=8) -> str
Return a copy of S where all tab characters are expanded using spaces.
If tabsize is not given, a tab size of 8 characters is assumed."""
return ""
def find(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""S.find(sub[, start[, end]]) -> int
Return the lowest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure."""
return0def format(self, *args, **kwargs): #known special case of str.format
"""S.format(*args, **kwargs) -> str
Return a formatted version of S, using substitutions from args and kwargs.
The substitutions are identified by braces ('{' and '}')."""
pass
def format_map(self, mapping): #real signature unknown; restored from __doc__
"""S.format_map(mapping) -> str
Return a formatted version of S, using substitutions from mapping.
The substitutions are identified by braces ('{' and '}')."""
return ""
def index(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""S.index(sub[, start[, end]]) -> int
Like S.find() but raise ValueError when the substring is not found."""
return0def isalnum(self): #real signature unknown; restored from __doc__
"""S.isalnum() -> bool
Return True if all characters in S are alphanumeric
and there is at least one character in S, False otherwise."""
returnFalsedef isalpha(self): #real signature unknown; restored from __doc__
"""S.isalpha() -> bool
Return True if all characters in S are alphabetic
and there is at least one character in S, False otherwise."""
returnFalsedef isdecimal(self): #real signature unknown; restored from __doc__
"""S.isdecimal() -> bool
Return True if there are only decimal characters in S,
False otherwise."""
returnFalsedef isdigit(self): #real signature unknown; restored from __doc__
"""S.isdigit() -> bool
Return True if all characters in S are digits
and there is at least one character in S, False otherwise."""
returnFalsedef isidentifier(self): #real signature unknown; restored from __doc__
"""S.isidentifier() -> bool
Return True if S is a valid identifier according
to the language definition.
Use keyword.iskeyword() to test for reserved identifiers
such as "def" and "class"."""
returnFalsedef islower(self): #real signature unknown; restored from __doc__
"""S.islower() -> bool
Return True if all cased characters in S are lowercase and there is
at least one cased character in S, False otherwise."""
returnFalsedef isnumeric(self): #real signature unknown; restored from __doc__
"""S.isnumeric() -> bool
Return True if there are only numeric characters in S,
False otherwise."""
returnFalsedef isprintable(self): #real signature unknown; restored from __doc__
"""S.isprintable() -> bool
Return True if all characters in S are considered
printable in repr() or S is empty, False otherwise."""
returnFalsedef isspace(self): #real signature unknown; restored from __doc__
"""S.isspace() -> bool
Return True if all characters in S are whitespace
and there is at least one character in S, False otherwise."""
returnFalsedef istitle(self): #real signature unknown; restored from __doc__
"""S.istitle() -> bool
Return True if S is a titlecased string and there is at least one
character in S, i.e. upper- and titlecase characters may only
follow uncased characters and lowercase characters only cased ones.
Return False otherwise."""
returnFalsedef isupper(self): #real signature unknown; restored from __doc__
"""S.isupper() -> bool
Return True if all cased characters in S are uppercase and there is
at least one cased character in S, False otherwise."""
returnFalsedef join(self, iterable): #real signature unknown; restored from __doc__
"""S.join(iterable) -> str
Return a string which is the concatenation of the strings in the
iterable. The separator between elements is S."""
return ""
def ljust(self, width, fillchar=None): #real signature unknown; restored from __doc__
"""S.ljust(width[, fillchar]) -> str
Return S left-justified in a Unicode string of length width. Padding is
done using the specified fill character (default is a space)."""
return ""
def lower(self): #real signature unknown; restored from __doc__
"""S.lower() -> str
Return a copy of the string S converted to lowercase."""
return ""
def lstrip(self, chars=None): #real signature unknown; restored from __doc__
"""S.lstrip([chars]) -> str
Return a copy of the string S with leading whitespace removed.
If chars is given and not None, remove characters in chars instead."""
return ""
def maketrans(self, *args, **kwargs): #real signature unknown
"""Return a translation table usable for str.translate().
If there is only one argument, it must be a dictionary mapping Unicode
ordinals (integers) or characters to Unicode ordinals, strings or None.
Character keys will be then converted to ordinals.
If there are two arguments, they must be strings of equal length, and
in the resulting dictionary, each character in x will be mapped to the
character at the same position in y. If there is a third argument, it
must be a string, whose characters will be mapped to None in the result."""
pass
def partition(self, sep): #real signature unknown; restored from __doc__
"""S.partition(sep) -> (head, sep, tail)
Search for the separator sep in S, and return the part before it,
the separator itself, and the part after it. If the separator is not
found, return S and two empty strings."""
pass
def replace(self, old, new, count=None): #real signature unknown; restored from __doc__
"""S.replace(old, new[, count]) -> str
Return a copy of S with all occurrences of substring
old replaced by new. If the optional argument count is
given, only the first count occurrences are replaced."""
return ""
def rfind(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""S.rfind(sub[, start[, end]]) -> int
Return the highest index in S where substring sub is found,
such that sub is contained within S[start:end]. Optional
arguments start and end are interpreted as in slice notation.
Return -1 on failure."""
return0def rindex(self, sub, start=None, end=None): #real signature unknown; restored from __doc__
"""S.rindex(sub[, start[, end]]) -> int
Like S.rfind() but raise ValueError when the substring is not found."""
return0def rjust(self, width, fillchar=None): #real signature unknown; restored from __doc__
"""S.rjust(width[, fillchar]) -> str
Return S right-justified in a string of length width. Padding is
done using the specified fill character (default is a space)."""
return ""
def rpartition(self, sep): #real signature unknown; restored from __doc__
"""S.rpartition(sep) -> (head, sep, tail)
Search for the separator sep in S, starting at the end of S, and return
the part before it, the separator itself, and the part after it. If the
separator is not found, return two empty strings and S."""
pass
def rsplit(self, sep=None, maxsplit=-1): #real signature unknown; restored from __doc__
"""S.rsplit(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string, starting at the end of the string and
working to the front. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified, any whitespace string
is a separator."""
return[]def rstrip(self, chars=None): #real signature unknown; restored from __doc__
"""S.rstrip([chars]) -> str
Return a copy of the string S with trailing whitespace removed.
If chars is given and not None, remove characters in chars instead."""
return ""
def split(self, sep=None, maxsplit=-1): #real signature unknown; restored from __doc__
"""S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the words in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result."""
return[]def splitlines(self, keepends=None): #real signature unknown; restored from __doc__
"""S.splitlines([keepends]) -> list of strings
Return a list of the lines in S, breaking at line boundaries.
Line breaks are not included in the resulting list unless keepends
is given and true."""
return[]def startswith(self, prefix, start=None, end=None): #real signature unknown; restored from __doc__
"""S.startswith(prefix[, start[, end]]) -> bool
Return True if S starts with the specified prefix, False otherwise.
With optional start, test S beginning at that position.
With optional end, stop comparing S at that position.
prefix can also be a tuple of strings to try."""
returnFalsedef strip(self, chars=None): #real signature unknown; restored from __doc__
"""S.strip([chars]) -> str
Return a copy of the string S with leading and trailing
whitespace removed.
If chars is given and not None, remove characters in chars instead."""
return ""
def swapcase(self): #real signature unknown; restored from __doc__
"""S.swapcase() -> str
Return a copy of S with uppercase characters converted to lowercase
and vice versa."""
return ""
def title(self): #real signature unknown; restored from __doc__
"""S.title() -> str
Return a titlecased version of S, i.e. words start with title case
characters, all remaining cased characters have lower case."""
return ""
def translate(self, table): #real signature unknown; restored from __doc__
"""S.translate(table) -> str
Return a copy of the string S in which each character has been mapped
through the given translation table. The table must implement
lookup/indexing via __getitem__, for instance a dictionary or list,
mapping Unicode ordinals to Unicode ordinals, strings, or None. If
this operation raises LookupError, the character is left untouched.
Characters mapped to None are deleted."""
return ""
def upper(self): #real signature unknown; restored from __doc__
"""S.upper() -> str
Return a copy of S converted to uppercase."""
return ""
def zfill(self, width): #real signature unknown; restored from __doc__
"""S.zfill(width) -> str
Pad a numeric string S with zeros on the left, to fill a field
of the specified width. The string S is never truncated."""
return ""
def __add__(self, *args, **kwargs): #real signature unknown
"""Return self+value."""
pass
def __contains__(self, *args, **kwargs): #real signature unknown
"""Return key in self."""
pass
def __eq__(self, *args, **kwargs): #real signature unknown
"""Return self==value."""
pass
def __format__(self, format_spec): #real signature unknown; restored from __doc__
"""S.__format__(format_spec) -> str
Return a formatted version of S as described by format_spec."""
return ""
def __getattribute__(self, *args, **kwargs): #real signature unknown
"""Return getattr(self, name)."""
pass
def __getitem__(self, *args, **kwargs): #real signature unknown
"""Return self[key]."""
pass
def __getnewargs__(self, *args, **kwargs): #real signature unknown
pass
def __ge__(self, *args, **kwargs): #real signature unknown
"""Return self>=value."""
pass
def __gt__(self, *args, **kwargs): #real signature unknown
"""Return self>value."""
pass
def __hash__(self, *args, **kwargs): #real signature unknown
"""Return hash(self)."""
pass
def __init__(self, value='', encoding=None, errors='strict'): #known special case of str.__init__
"""str(object='') -> str
str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or
errors is specified, then the object must expose a data buffer
that will be decoded using the given encoding and error handler.
Otherwise, returns the result of object.__str__() (if defined)
or repr(object).
encoding defaults to sys.getdefaultencoding().
errors defaults to 'strict'.
# (copied from class doc)"""
pass
def __iter__(self, *args, **kwargs): #real signature unknown
"""Implement iter(self)."""
pass
def __len__(self, *args, **kwargs): #real signature unknown
"""Return len(self)."""
pass
def __le__(self, *args, **kwargs): #real signature unknown
"""Return self<=value."""
pass
def __lt__(self, *args, **kwargs): #real signature unknown
"""Return self
pass
def __mod__(self, *args, **kwargs): #real signature unknown
"""Return self%value."""
pass
def __mul__(self, *args, **kwargs): #real signature unknown
"""Return self*value.n"""
pass@staticmethod#known case of __new__
def __new__(*args, **kwargs): #real signature unknown
"""Create and return a new object. See help(type) for accurate signature."""
pass
def __ne__(self, *args, **kwargs): #real signature unknown
"""Return self!=value."""
pass
def __repr__(self, *args, **kwargs): #real signature unknown
"""Return repr(self)."""
pass
def __rmod__(self, *args, **kwargs): #real signature unknown
"""Return value%self."""
pass
def __rmul__(self, *args, **kwargs): #real signature unknown
"""Return self*value."""
pass
def __sizeof__(self): #real signature unknown; restored from __doc__
"""S.__sizeof__() -> size of S in memory, in bytes"""
pass
def __str__(self, *args, **kwargs): #real signature unknown
"""Return str(self)."""
pass
View Code
字符串表達形式
# 空字符串
s = ''s = ""
# 字符串中包含引號
s = "what’s your name"s = 'my name is "lianglian"'
# 三重引號字符串塊
s = """
Infomation of user lianglian:
-------------------
Name: lianglian
Age : 12
Job : IT
---------End-------
"""
# Raw字符串,可以對字符串中得特殊字符轉義
s = r"lianglian"
# Unicode字符串
s = u"lianglian"
# 字節字符串
s = b"lianglian"
字符串操作
# 字符串拼接
s1 = "liang"s2 = "lian"
print(s1 + s2)
lianglian
# 萬惡得“+”號
print("a" + "b" + "c") # 會開辟三塊地址空間 ,這個和上面得方法還是有區別的,上面是將本來存在地址空間得兩個數據拼接起來,而這個是在一次print操作中使用"+"拼接字符串會開辟多個新的空間。
abc
# 字符串重復
s1 = "liang"s2 = "lian"
print(s1 * 3)
liangliangliang
# 字符串索引
s = "lianglian"
print(s[0])
s = "lianglian"
print(s[0:3])
l
lia
# 獲取字符串長度
s = "lianglian"
print(len(s))
9
# 字符串格式化
s = "my name is:%s"
print(s % "lianglian")
# 字符串format方法格式化字符串
s = "my name is:{name}"
print(s.format(name="liangian"))
my name is:lianglian
my name is:liangian
# 字符串find方法得到字符在字符串中得索引
s = "my name is:{name}"
print(s.find("a"))
4
# 字符串strip方法去除字符串兩端得空格
s = " liang lian "
print(s.strip())
liang lian
# 字符串split方法分隔字符串返回list
s = " liang lian "
print(s.split())
['liang', 'lian']
# 字符串join方法來對字符串進行拼接
s = "liang lian"s = s.split() # 分隔字符串
s1 = "|".join(s) # 拼接字符串
print(s1)
liang|lian
# 字符串replace方法達到字符串替換
s = "liang lian"
print(s.replace("liang","lian"))
lian lian
# 字符串center方法來對字符串居中
s = "liang lian"
print(s.center(50, '*')) # 居中并且用"*"填充
********************liang lian********************
# 字符串capitalize方法使字符串第一個字母大寫
s = "liang lian"
print(s.capitalize())
Liang lian
# 判斷字符串中是否有空格
s = "liang lian"
print("" in s)
True
# 字符串isdigt方法來判斷字符串是不是數字
s = "liang lian"
print(s.isdigit())
s1 = "45"
print(s1.isdigit())
False
True
# 字符串startswith方法判斷字符串是以什么開頭的
s = "liang lian"
print(s.startswith("l"))
True
# 字符串endswith方法判斷字符串是以什么結尾的
s = "liang lian"
print(s.endswith("n"))
True
二、元組(tuple)
元組是一個不可更改得有序得序列,支持任意類型得,任意嵌套數據
元組得輸寫格式:用小括號括起來(1,2,3,"liang")
所有元組可以調用的方法:
tuple
classtuple(object):"""tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items
If the argument is a tuple, the return value is the same object."""
def count(self, value): #real signature unknown; restored from __doc__
"""T.count(value) -> integer -- return number of occurrences of value"""
return0def index(self, value, start=None, stop=None): #real signature unknown; restored from __doc__
"""T.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present."""
return0def __add__(self, *args, **kwargs): #real signature unknown
"""Return self+value."""
pass
def __contains__(self, *args, **kwargs): #real signature unknown
"""Return key in self."""
pass
def __eq__(self, *args, **kwargs): #real signature unknown
"""Return self==value."""
pass
def __getattribute__(self, *args, **kwargs): #real signature unknown
"""Return getattr(self, name)."""
pass
def __getitem__(self, *args, **kwargs): #real signature unknown
"""Return self[key]."""
pass
def __getnewargs__(self, *args, **kwargs): #real signature unknown
pass
def __ge__(self, *args, **kwargs): #real signature unknown
"""Return self>=value."""
pass
def __gt__(self, *args, **kwargs): #real signature unknown
"""Return self>value."""
pass
def __hash__(self, *args, **kwargs): #real signature unknown
"""Return hash(self)."""
pass
def __init__(self, seq=()): #known special case of tuple.__init__
"""tuple() -> empty tuple
tuple(iterable) -> tuple initialized from iterable's items
If the argument is a tuple, the return value is the same object.
# (copied from class doc)"""
pass
def __iter__(self, *args, **kwargs): #real signature unknown
"""Implement iter(self)."""
pass
def __len__(self, *args, **kwargs): #real signature unknown
"""Return len(self)."""
pass
def __le__(self, *args, **kwargs): #real signature unknown
"""Return self<=value."""
pass
def __lt__(self, *args, **kwargs): #real signature unknown
"""Return self
pass
def __mul__(self, *args, **kwargs): #real signature unknown
"""Return self*value.n"""
pass@staticmethod#known case of __new__
def __new__(*args, **kwargs): #real signature unknown
"""Create and return a new object. See help(type) for accurate signature."""
pass
def __ne__(self, *args, **kwargs): #real signature unknown
"""Return self!=value."""
pass
def __repr__(self, *args, **kwargs): #real signature unknown
"""Return repr(self)."""
pass
def __rmul__(self, *args, **kwargs): #real signature unknown
"""Return self*value."""
pass
View Code
創建元組
#創建元組
t = (1, 2, 3, "lianglian")print(t)
t1= tuple([1, 2, 3, "lianlgian"]) #tuple將其它序列轉換成元組
print(t1)
t2= (1, 2, 3, 4, 5, 6, 7, 8, 9, (1, 2, 3)) #創建嵌套元組
print(t * 3) #元組復制
t3= t + t2 #元組合并
print(t3)
元組分片[起始位:結束位:步長]
t = (1, 2, 3, 4, 5, 6, 7, 8, 9, (1,2,3))print(t[0]) #[]中輸入索引進行分片,索引起始位為0
print(t[3:6]) #顯示4~6得元素
print(t[3:]) #顯示4到最后
print(t[:6]) #顯示從開頭到7
print(t[-1]) #顯示倒數第一個
print(t[-4:-2]) #顯示倒數第4個到倒數第二個,(**范圍切片,結束位不包括在內,即"到什么什么之前"**)
print(t[:]) #顯示全部
print(t[::2]) #按照步長為2,顯示全部,**步長即兩個元素之間索引閑差多少執行一次**
print(t[9][0]) #嵌套分片
1
(4, 5, 6)
(4, 5, 6, 7, 8, 9, (1, 2, 3))
(1, 2, 3, 4, 5, 6)
(1, 2, 3)
(7, 8)
(1, 2, 3, 4, 5, 6, 7, 8, 9, (1, 2, 3))
(1, 3, 5, 7, 9)
1
元組操作
#查找元素相對應得索引
t = (1, 2, 3, "lianglian")print(t.index("lianglian"))
3
#查看元素在元組中得數量
t = (1, 2, 3, "lianglian", 3,)print(t.count(3))
2
三、列表(list)
list是Python中最靈活的有序的集合,列表可以包含任何類型得對象:數字、字符串、甚至其它列表。支持在原處修改(可修改的),也可以進行分片操作。
list
classlist(object):"""list() -> new empty list
list(iterable) -> new list initialized from iterable's items"""
def append(self, p_object): #real signature unknown; restored from __doc__
"""L.append(object) -> None -- append object to end"""
pass
def clear(self): #real signature unknown; restored from __doc__
"""L.clear() -> None -- remove all items from L"""
pass
def copy(self): #real signature unknown; restored from __doc__
"""L.copy() -> list -- a shallow copy of L"""
return[]def count(self, value): #real signature unknown; restored from __doc__
"""L.count(value) -> integer -- return number of occurrences of value"""
return0def extend(self, iterable): #real signature unknown; restored from __doc__
"""L.extend(iterable) -> None -- extend list by appending elements from the iterable"""
pass
def index(self, value, start=None, stop=None): #real signature unknown; restored from __doc__
"""L.index(value, [start, [stop]]) -> integer -- return first index of value.
Raises ValueError if the value is not present."""
return0def insert(self, index, p_object): #real signature unknown; restored from __doc__
"""L.insert(index, object) -- insert object before index"""
pass
def pop(self, index=None): #real signature unknown; restored from __doc__
"""L.pop([index]) -> item -- remove and return item at index (default last).
Raises IndexError if list is empty or index is out of range."""
pass
def remove(self, value): #real signature unknown; restored from __doc__
"""L.remove(value) -> None -- remove first occurrence of value.
Raises ValueError if the value is not present."""
pass
def reverse(self): #real signature unknown; restored from __doc__
"""L.reverse() -- reverse *IN PLACE*"""
pass
def sort(self, key=None, reverse=False): #real signature unknown; restored from __doc__
"""L.sort(key=None, reverse=False) -> None -- stable sort *IN PLACE*"""
pass
def __add__(self, *args, **kwargs): #real signature unknown
"""Return self+value."""
pass
def __contains__(self, *args, **kwargs): #real signature unknown
"""Return key in self."""
pass
def __delitem__(self, *args, **kwargs): #real signature unknown
"""Delete self[key]."""
pass
def __eq__(self, *args, **kwargs): #real signature unknown
"""Return self==value."""
pass
def __getattribute__(self, *args, **kwargs): #real signature unknown
"""Return getattr(self, name)."""
pass
def __getitem__(self, y): #real signature unknown; restored from __doc__
"""x.__getitem__(y) <==> x[y]"""
pass
def __ge__(self, *args, **kwargs): #real signature unknown
"""Return self>=value."""
pass
def __gt__(self, *args, **kwargs): #real signature unknown
"""Return self>value."""
pass
def __iadd__(self, *args, **kwargs): #real signature unknown
"""Implement self+=value."""
pass
def __imul__(self, *args, **kwargs): #real signature unknown
"""Implement self*=value."""
pass
def __init__(self, seq=()): #known special case of list.__init__
"""list() -> new empty list
list(iterable) -> new list initialized from iterable's items
# (copied from class doc)"""
pass
def __iter__(self, *args, **kwargs): #real signature unknown
"""Implement iter(self)."""
pass
def __len__(self, *args, **kwargs): #real signature unknown
"""Return len(self)."""
pass
def __le__(self, *args, **kwargs): #real signature unknown
"""Return self<=value."""
pass
def __lt__(self, *args, **kwargs): #real signature unknown
"""Return self
pass
def __mul__(self, *args, **kwargs): #real signature unknown
"""Return self*value.n"""
pass@staticmethod#known case of __new__
def __new__(*args, **kwargs): #real signature unknown
"""Create and return a new object. See help(type) for accurate signature."""
pass
def __ne__(self, *args, **kwargs): #real signature unknown
"""Return self!=value."""
pass
def __repr__(self, *args, **kwargs): #real signature unknown
"""Return repr(self)."""
pass
def __reversed__(self): #real signature unknown; restored from __doc__
"""L.__reversed__() -- return a reverse iterator over the list"""
pass
def __rmul__(self, *args, **kwargs): #real signature unknown
"""Return self*value."""
pass
def __setitem__(self, *args, **kwargs): #real signature unknown
"""Set self[key] to value."""
pass
def __sizeof__(self): #real signature unknown; restored from __doc__
"""L.__sizeof__() -- size of L in memory, in bytes"""
pass
__hash__ = None
View Code
創建list
# list書寫格式用[]包裹起來,元素與元素之間用","分隔
l = []
print(type(l)) # type()函數查看類型
# list可以將其它序列轉換成列表
l = list((1,2,3,4))
print(l)
print(type(l))
[1, 2, 3, 4]
list操作
#列表append方法對列表進行添加元素操作
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.append('alex')print(group)
['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛', 'alex']
#列表pop方法刪除列表的最后一個元素
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.pop()print(group)
['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連']
#列表remove方法刪除列表指定元素
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.remove('梁連')print(group)
['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '趙鴻飛']
#列表index方法獲取指定元素索引
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']print(group.index('梁連'))
6
#列表count方法查看指定元素在列表中數量
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.append('梁連')print(group)print(group.count('梁連'))
['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛', '梁連']
2
#列表extend方法拼接列表
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
tmp_group= ['alex', '武sir']
group.extend(tmp_group)print(group)
['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛', 'alex', '武sir']
#列表sort方法對列表進行排序
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.sort()print(group)
['杜保強', '榪棟勝', '梁連', '潘東林', '潘文斌', '牛恒博', '田杰', '趙鴻飛']
#列表reverse方法對列表進行反轉
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.reverse()print(group)
['趙鴻飛', '梁連', '杜保強', '牛恒博', '潘東林', '榪棟勝', '田杰', '潘文斌']
#列表insert方法在列表中插入新的元素
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.insert(1, 'alex') #在索引1插入一個新的元素,之前索引1的元素向后移
print(group)
['潘文斌', 'alex', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
#列表clear方法清空列表
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group.clear()print(group)
[]
#列表分片操作
group = ['潘文斌', '田杰', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
group[1] = "tianjie" #修改列表索引1的元素
print(group)del group[3:] #del 關鍵字可以刪除python對象中在內存得數據
print(group)
['潘文斌', 'tianjie', '榪棟勝', '潘東林', '牛恒博', '杜保強', '梁連', '趙鴻飛']
['潘文斌', 'tianjie', '榪棟勝']
#遍歷列表,將"9"全部替換成"999"
name = ['Alex', 'Jack', 'Rain', [9, 4, 3, 5], 9]for num inname:if num == 9:
key=name.index(num)
name[key]= 9999
elif type(num) ==list:
index=name.index(num)for num1 innum:if num1 == 9:
index1=num.index(num1)
name[index][index1]= 9999
print(name)
['Alex', 'Jack', 'Rain', [9999, 4, 3, 5], 9999]
四、集合(set)
python 的 set 和其他語言類似, 是一個無序不重復元素集, 基本功能包括關系測 試和消除重復元素. 集合對象還支持 union(聯合), intersection(交), difference(差) 和 sysmmetric difference(對稱差集)等數學運算.
sets 支持 x in set, len(set),和 for x in set。作為一個無序的集合,sets 不記錄元 素位置或者插入點。因此,sets 不支持 indexing, slicing, 或其它類序列 (sequence-like)的操作。
與列表和元組不同,集合是無序的,也無法通過數字進行索引。此外,集合中的 元素不能重復:
s = set("Hello")print(s)
{'l', 'o', 'H', 'e'}
如上結果中少了一個"l",set是會默認去除重復的。
set
classset(object):"""set() -> new empty set object
set(iterable) -> new set object
Build an unordered collection of unique elements."""
def add(self, *args, **kwargs): #real signature unknown
"""Add an element to a set.
This has no effect if the element is already present."""
pass
def clear(self, *args, **kwargs): #real signature unknown
"""Remove all elements from this set."""
pass
def copy(self, *args, **kwargs): #real signature unknown
"""Return a shallow copy of a set."""
pass
def difference(self, *args, **kwargs): #real signature unknown
"""Return the difference of two or more sets as a new set.
(i.e. all elements that are in this set but not the others.)"""
pass
def difference_update(self, *args, **kwargs): #real signature unknown
"""Remove all elements of another set from this set."""
pass
def discard(self, *args, **kwargs): #real signature unknown
"""Remove an element from a set if it is a member.
If the element is not a member, do nothing."""
pass
def intersection(self, *args, **kwargs): #real signature unknown
"""Return the intersection of two sets as a new set.
(i.e. all elements that are in both sets.)"""
pass
def intersection_update(self, *args, **kwargs): #real signature unknown
"""Update a set with the intersection of itself and another."""
pass
def isdisjoint(self, *args, **kwargs): #real signature unknown
"""Return True if two sets have a null intersection."""
pass
def issubset(self, *args, **kwargs): #real signature unknown
"""Report whether another set contains this set."""
pass
def issuperset(self, *args, **kwargs): #real signature unknown
"""Report whether this set contains another set."""
pass
def pop(self, *args, **kwargs): #real signature unknown
"""Remove and return an arbitrary set element.
Raises KeyError if the set is empty."""
pass
def remove(self, *args, **kwargs): #real signature unknown
"""Remove an element from a set; it must be a member.
If the element is not a member, raise a KeyError."""
pass
def symmetric_difference(self, *args, **kwargs): #real signature unknown
"""Return the symmetric difference of two sets as a new set.
(i.e. all elements that are in exactly one of the sets.)"""
pass
def symmetric_difference_update(self, *args, **kwargs): #real signature unknown
"""Update a set with the symmetric difference of itself and another."""
pass
def union(self, *args, **kwargs): #real signature unknown
"""Return the union of sets as a new set.
(i.e. all elements that are in either set.)"""
pass
def update(self, *args, **kwargs): #real signature unknown
"""Update a set with the union of itself and others."""
pass
def __and__(self, *args, **kwargs): #real signature unknown
"""Return self&value."""
pass
def __contains__(self, y): #real signature unknown; restored from __doc__
"""x.__contains__(y) <==> y in x."""
pass
def __eq__(self, *args, **kwargs): #real signature unknown
"""Return self==value."""
pass
def __getattribute__(self, *args, **kwargs): #real signature unknown
"""Return getattr(self, name)."""
pass
def __ge__(self, *args, **kwargs): #real signature unknown
"""Return self>=value."""
pass
def __gt__(self, *args, **kwargs): #real signature unknown
"""Return self>value."""
pass
def __iand__(self, *args, **kwargs): #real signature unknown
"""Return self&=value."""
pass
def __init__(self, seq=()): #known special case of set.__init__
"""set() -> new empty set object
set(iterable) -> new set object
Build an unordered collection of unique elements.
# (copied from class doc)"""
pass
def __ior__(self, *args, **kwargs): #real signature unknown
"""Return self|=value."""
pass
def __isub__(self, *args, **kwargs): #real signature unknown
"""Return self-=value."""
pass
def __iter__(self, *args, **kwargs): #real signature unknown
"""Implement iter(self)."""
pass
def __ixor__(self, *args, **kwargs): #real signature unknown
"""Return self^=value."""
pass
def __len__(self, *args, **kwargs): #real signature unknown
"""Return len(self)."""
pass
def __le__(self, *args, **kwargs): #real signature unknown
"""Return self<=value."""
pass
def __lt__(self, *args, **kwargs): #real signature unknown
"""Return self
pass@staticmethod#known case of __new__
def __new__(*args, **kwargs): #real signature unknown
"""Create and return a new object. See help(type) for accurate signature."""
pass
def __ne__(self, *args, **kwargs): #real signature unknown
"""Return self!=value."""
pass
def __or__(self, *args, **kwargs): #real signature unknown
"""Return self|value."""
pass
def __rand__(self, *args, **kwargs): #real signature unknown
"""Return value&self."""
pass
def __reduce__(self, *args, **kwargs): #real signature unknown
"""Return state information for pickling."""
pass
def __repr__(self, *args, **kwargs): #real signature unknown
"""Return repr(self)."""
pass
def __ror__(self, *args, **kwargs): #real signature unknown
"""Return value|self."""
pass
def __rsub__(self, *args, **kwargs): #real signature unknown
"""Return value-self."""
pass
def __rxor__(self, *args, **kwargs): #real signature unknown
"""Return value^self."""
pass
def __sizeof__(self): #real signature unknown; restored from __doc__
"""S.__sizeof__() -> size of S in memory, in bytes"""
pass
def __sub__(self, *args, **kwargs): #real signature unknown
"""Return self-value."""
pass
def __xor__(self, *args, **kwargs): #real signature unknown
"""Return self^value."""
pass
__hash__ = None
View Code
#集合標準操作
s = set("Hello")
t= set("World")print(s.union(t)) #s 和 t的并集(兩個合并到一塊)
print(s | t) #簡寫
print(s.intersection(t)) #s 和 t的交集(取出兩個都有的)
print(s &t)print(s.difference(t)) #求差集(項在s中,但是不在t中)
print(s -t)print(s.symmetric_difference(t)) #對稱差集(兩個中不相同的)
print(s ^ t)
{'r', 'l', 'o', 'd', 'e', 'W', 'H'}
{'l', 'o'}
{'H', 'e'}
{'r', 'd', 'e', 'W', 'H'}
#集合add方法添加新元素
t = set("Hello")
t.add("x")print(t)
{'H', 'x', 'o', 'l', 'e'}
#集合aupdate方法添加多個元素,可以接受迭代的對象,循環add,批量添加#add update 的區別
t = set("Hello")
t.add("world")print(t)
t1= set("Hello")
t1.update("world")print(t1)
{'l', 'H', 'e', 'world', 'o'}
{'l', 'H', 'd', 'e', 'w', 'o', 'r'}
#差集更新(在s中有的,在t中沒有更新到s)
s = set("Hello")
t= set("World")print(s)
s.difference_update(t)print(s)
{'H', 'o', 'l', 'e'}
{'H', 'e'}
#集合remove方法,移除指定值,如果沒有會報錯
s = set("Hello")
s.remove("H")print(s)
{'l', 'e', 'o'}
#集合discard方法,移除指定值,如果沒有會報錯
s = set("Hello")
s.discard("h")print(s)
{'l', 'e', 'o', 'H'}
old_dict ={"#1": 8,"#2": 4,"#4": 2,
}
new_dict={"#1": 4,"#2": 4,"#3": 2,
}#old_dict 中沒有, new_dict 中有的加到 old_dict
old_set=set(old_dict.keys())
new_set=set(new_dict.keys())
remove_set=old_set.difference(new_set)
add_set=new_set.difference(old_set)
update_set=old_set.intersection(new_set)print("刪除:%s\n添加:%s\n更新%s\n" % (remove_set, add_set, update_set))
刪除:{'#4'}
添加:{'#3'}
更新{'#1', '#2'}
五、運算
算數運算:
比較運算:
賦值運算:
邏輯運算:
成員運算:
身份運算:
位運算:
運算優先級:
總結
以上是生活随笔為你收集整理的python输入三角形三边处理成三个实数_Python之路:(三)数据处理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php编程输出心形图案_利用php输出不
- 下一篇: 百度富文本编辑jsp上传_百度富文本编辑