首页 > 代码库 > Python基本数据类型

Python基本数据类型

元组,列表,字典,集合

一:什么是数据类型

x =  10,10是我们要存储的数据

二:数据类型

数字(整型,长整型,浮点型,复数)

字符串

列表

元组

字典

集合

Bytes类型

(一):数字(int,float,complex)

作用:年纪,等级,薪资,身份证号,qq号等数字相关

print(bin(10))#将10进制转换成二进制
print(oct(10))#将10进制转换成8进制
print(hex(10))#将10进制转换成16进制
#0b1010
#0o12
#0xa

(二):字符串(str)
字符串的常用操作
移除空白
分割
长度
索引
切片
技术分享
class str(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.
        """
        return 0

    def 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.
        """
        return False

    def 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.
        """
        return 0

    def 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.
        """
        return 0

    def 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.
        """
        return False

    def 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.
        """
        return False

    def isdecimal(self): # real signature unknown; restored from __doc__
        """
        S.isdecimal() -> bool
        
        Return True if there are only decimal characters in S,
        False otherwise.
        """
        return False

    def 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.
        """
        return False

    def 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".
        """
        return False

    def 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.
        """
        return False

    def isnumeric(self): # real signature unknown; restored from __doc__
        """
        S.isnumeric() -> bool
        
        Return True if there are only numeric characters in S,
        False otherwise.
        """
        return False

    def 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.
        """
        return False

    def 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.
        """
        return False

    def 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.
        """
        return False

    def 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.
        """
        return False

    def 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.
        """
        return 0

    def 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.
        """
        return 0

    def 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.
        """
        return False

    def 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=http://www.mamicode.com/‘‘, 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<value. """
        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


class super(object):
    """
    super() -> same as super(__class__, <first argument>)
    super(type) -> unbound super object
    super(type, obj) -> bound super object; requires isinstance(obj, type)
    super(type, type2) -> bound super object; requires issubclass(type2, type)
    Typical use to call a cooperative superclass method:
    class C(B):
        def meth(self, arg):
            super().meth(arg)
    This works for class methods too:
    class C(B):
        @classmethod
        def cmeth(cls, arg):
            super().cmeth(arg)
    """
    def __getattribute__(self, *args, **kwargs): # real signature unknown
        """ Return getattr(self, name). """
        pass

    def __get__(self, *args, **kwargs): # real signature unknown
        """ Return an attribute of instance, which is of type owner. """
        pass

    def __init__(self, type1=None, type2=None): # known special case of super.__init__
        """
        super() -> same as super(__class__, <first argument>)
        super(type) -> unbound super object
        super(type, obj) -> bound super object; requires isinstance(obj, type)
        super(type, type2) -> bound super object; requires issubclass(type2, type)
        Typical use to call a cooperative superclass method:
        class C(B):
            def meth(self, arg):
                super().meth(arg)
        This works for class methods too:
        class C(B):
            @classmethod
            def cmeth(cls, arg):
                super().cmeth(arg)
        
        # (copied from class doc)
        """
        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 __repr__(self, *args, **kwargs): # real signature unknown
        """ Return repr(self). """
        pass

    __self_class__ = property(lambda self: type(object))
    """the type of the instance invoking super(); may be None

    :type: type
    """

    __self__ = property(lambda self: type(object))
    """the instance invoking super(); may be None

    :type: type
    """

    __thisclass__ = property(lambda self: type(object))
    """the class invoking super()

    :type: type
    """



class SyntaxWarning(Warning):
    """ Base class for warnings about dubious syntax. """
    def __init__(self, *args, **kwargs): # real signature unknown
        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


class SystemError(Exception):
    """
    Internal error in the Python interpreter.
    
    Please report this to the Python maintainer, along with the traceback,
    the Python version, and the hardware/OS platform and version.
    """
    def __init__(self, *args, **kwargs): # real signature unknown
        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


class SystemExit(BaseException):
    """ Request to exit from the interpreter. """
    def __init__(self, *args, **kwargs): # real signature unknown
        pass

    code = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
    """exception code"""



class TabError(IndentationError):
    """ Improper mixture of spaces and tabs. """
    def __init__(self, *args, **kwargs): # real signature unknown
        pass


class TimeoutError(OSError):
    """ Timeout expired. """
    def __init__(self, *args, **kwargs): # real signature unknown
        pass
View Code

#移除空白
name = ‘ egon‘
print(name.strip())##取出两边的空白
name = ‘*egon‘
print(name.strip(‘*‘))##移除制定的字符

#分割
info = ‘root:x:0:0::/root:/bin/bash‘
user_info.split(‘:‘)#以冒号作为切个字符
print(user_info.split(‘:‘))
cmd_info = ‘get|a.txt|33333‘
print(cmd_info.split(‘|‘))##以|为切分字符
print(cmd_info.split(‘|‘,1))##制定的最大切分次数为1

#长度
name = ‘egon‘
print(len(name))

#切片
name = ‘egon‘
print(name[1:3])
  1 class str(object):
  2     """
  3     str(object=‘‘) -> str
  4     str(bytes_or_buffer[, encoding[, errors]]) -> str
  5     
  6     Create a new string object from the given object. If encoding or
  7     errors is specified, then the object must expose a data buffer
  8     that will be decoded using the given encoding and error handler.
  9     Otherwise, returns the result of object.__str__() (if defined)
 10     or repr(object).
 11     encoding defaults to sys.getdefaultencoding().
 12     errors defaults to ‘strict‘.
 13     """
 14     def capitalize(self): # real signature unknown; restored from __doc__
 15         """
 16         S.capitalize() -> str
 17         
 18         Return a capitalized version of S, i.e. make the first character
 19         have upper case and the rest lower case.
 20         """
 21         return ""
 22 
 23     def casefold(self): # real signature unknown; restored from __doc__
 24         """
 25         S.casefold() -> str
 26         
 27         Return a version of S suitable for caseless comparisons.
 28         """
 29         return ""
 30 
 31     def center(self, width, fillchar=None): # real signature unknown; restored from __doc__
 32         """
 33         S.center(width[, fillchar]) -> str
 34         
 35         Return S centered in a string of length width. Padding is
 36         done using the specified fill character (default is a space)
 37         """
 38         return ""
 39 
 40     def count(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
 41         """
 42         S.count(sub[, start[, end]]) -> int
 43         
 44         Return the number of non-overlapping occurrences of substring sub in
 45         string S[start:end].  Optional arguments start and end are
 46         interpreted as in slice notation.
 47         """
 48         return 0
 49 
 50     def encode(self, encoding=utf-8, errors=strict): # real signature unknown; restored from __doc__
 51         """
 52         S.encode(encoding=‘utf-8‘, errors=‘strict‘) -> bytes
 53         
 54         Encode S using the codec registered for encoding. Default encoding
 55         is ‘utf-8‘. errors may be given to set a different error
 56         handling scheme. Default is ‘strict‘ meaning that encoding errors raise
 57         a UnicodeEncodeError. Other possible values are ‘ignore‘, ‘replace‘ and
 58         ‘xmlcharrefreplace‘ as well as any other name registered with
 59         codecs.register_error that can handle UnicodeEncodeErrors.
 60         """
 61         return b""
 62 
 63     def endswith(self, suffix, start=None, end=None): # real signature unknown; restored from __doc__
 64         """
 65         S.endswith(suffix[, start[, end]]) -> bool
 66         
 67         Return True if S ends with the specified suffix, False otherwise.
 68         With optional start, test S beginning at that position.
 69         With optional end, stop comparing S at that position.
 70         suffix can also be a tuple of strings to try.
 71         """
 72         return False
 73 
 74     def expandtabs(self, tabsize=8): # real signature unknown; restored from __doc__
 75         """
 76         S.expandtabs(tabsize=8) -> str
 77         
 78         Return a copy of S where all tab characters are expanded using spaces.
 79         If tabsize is not given, a tab size of 8 characters is assumed.
 80         """
 81         return ""
 82 
 83     def find(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
 84         """
 85         S.find(sub[, start[, end]]) -> int
 86         
 87         Return the lowest index in S where substring sub is found,
 88         such that sub is contained within S[start:end].  Optional
 89         arguments start and end are interpreted as in slice notation.
 90         
 91         Return -1 on failure.
 92         """
 93         return 0
 94 
 95     def format(self, *args, **kwargs): # known special case of str.format
 96         """
 97         S.format(*args, **kwargs) -> str
 98         
 99         Return a formatted version of S, using substitutions from args and kwargs.
100         The substitutions are identified by braces (‘{‘ and ‘}‘).
101         """
102         pass
103 
104     def format_map(self, mapping): # real signature unknown; restored from __doc__
105         """
106         S.format_map(mapping) -> str
107         
108         Return a formatted version of S, using substitutions from mapping.
109         The substitutions are identified by braces (‘{‘ and ‘}‘).
110         """
111         return ""
112 
113     def index(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
114         """
115         S.index(sub[, start[, end]]) -> int
116         
117         Like S.find() but raise ValueError when the substring is not found.
118         """
119         return 0
120 
121     def isalnum(self): # real signature unknown; restored from __doc__
122         """
123         S.isalnum() -> bool
124         
125         Return True if all characters in S are alphanumeric
126         and there is at least one character in S, False otherwise.
127         """
128         return False
129 
130     def isalpha(self): # real signature unknown; restored from __doc__
131         """
132         S.isalpha() -> bool
133         
134         Return True if all characters in S are alphabetic
135         and there is at least one character in S, False otherwise.
136         """
137         return False
138 
139     def isdecimal(self): # real signature unknown; restored from __doc__
140         """
141         S.isdecimal() -> bool
142         
143         Return True if there are only decimal characters in S,
144         False otherwise.
145         """
146         return False
147 
148     def isdigit(self): # real signature unknown; restored from __doc__
149         """
150         S.isdigit() -> bool
151         
152         Return True if all characters in S are digits
153         and there is at least one character in S, False otherwise.
154         """
155         return False
156 
157     def isidentifier(self): # real signature unknown; restored from __doc__
158         """
159         S.isidentifier() -> bool
160         
161         Return True if S is a valid identifier according
162         to the language definition.
163         
164         Use keyword.iskeyword() to test for reserved identifiers
165         such as "def" and "class".
166         """
167         return False
168 
169     def islower(self): # real signature unknown; restored from __doc__
170         """
171         S.islower() -> bool
172         
173         Return True if all cased characters in S are lowercase and there is
174         at least one cased character in S, False otherwise.
175         """
176         return False
177 
178     def isnumeric(self): # real signature unknown; restored from __doc__
179         """
180         S.isnumeric() -> bool
181         
182         Return True if there are only numeric characters in S,
183         False otherwise.
184         """
185         return False
186 
187     def isprintable(self): # real signature unknown; restored from __doc__
188         """
189         S.isprintable() -> bool
190         
191         Return True if all characters in S are considered
192         printable in repr() or S is empty, False otherwise.
193         """
194         return False
195 
196     def isspace(self): # real signature unknown; restored from __doc__
197         """
198         S.isspace() -> bool
199         
200         Return True if all characters in S are whitespace
201         and there is at least one character in S, False otherwise.
202         """
203         return False
204 
205     def istitle(self): # real signature unknown; restored from __doc__
206         """
207         S.istitle() -> bool
208         
209         Return True if S is a titlecased string and there is at least one
210         character in S, i.e. upper- and titlecase characters may only
211         follow uncased characters and lowercase characters only cased ones.
212         Return False otherwise.
213         """
214         return False
215 
216     def isupper(self): # real signature unknown; restored from __doc__
217         """
218         S.isupper() -> bool
219         
220         Return True if all cased characters in S are uppercase and there is
221         at least one cased character in S, False otherwise.
222         """
223         return False
224 
225     def join(self, iterable): # real signature unknown; restored from __doc__
226         """
227         S.join(iterable) -> str
228         
229         Return a string which is the concatenation of the strings in the
230         iterable.  The separator between elements is S.
231         """
232         return ""
233 
234     def ljust(self, width, fillchar=None): # real signature unknown; restored from __doc__
235         """
236         S.ljust(width[, fillchar]) -> str
237         
238         Return S left-justified in a Unicode string of length width. Padding is
239         done using the specified fill character (default is a space).
240         """
241         return ""
242 
243     def lower(self): # real signature unknown; restored from __doc__
244         """
245         S.lower() -> str
246         
247         Return a copy of the string S converted to lowercase.
248         """
249         return ""
250 
251     def lstrip(self, chars=None): # real signature unknown; restored from __doc__
252         """
253         S.lstrip([chars]) -> str
254         
255         Return a copy of the string S with leading whitespace removed.
256         If chars is given and not None, remove characters in chars instead.
257         """
258         return ""
259 
260     def maketrans(self, *args, **kwargs): # real signature unknown
261         """
262         Return a translation table usable for str.translate().
263         
264         If there is only one argument, it must be a dictionary mapping Unicode
265         ordinals (integers) or characters to Unicode ordinals, strings or None.
266         Character keys will be then converted to ordinals.
267         If there are two arguments, they must be strings of equal length, and
268         in the resulting dictionary, each character in x will be mapped to the
269         character at the same position in y. If there is a third argument, it
270         must be a string, whose characters will be mapped to None in the result.
271         """
272         pass
273 
274     def partition(self, sep): # real signature unknown; restored from __doc__
275         """
276         S.partition(sep) -> (head, sep, tail)
277         
278         Search for the separator sep in S, and return the part before it,
279         the separator itself, and the part after it.  If the separator is not
280         found, return S and two empty strings.
281         """
282         pass
283 
284     def replace(self, old, new, count=None): # real signature unknown; restored from __doc__
285         """
286         S.replace(old, new[, count]) -> str
287         
288         Return a copy of S with all occurrences of substring
289         old replaced by new.  If the optional argument count is
290         given, only the first count occurrences are replaced.
291         """
292         return ""
293 
294     def rfind(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
295         """
296         S.rfind(sub[, start[, end]]) -> int
297         
298         Return the highest index in S where substring sub is found,
299         such that sub is contained within S[start:end].  Optional
300         arguments start and end are interpreted as in slice notation.
301         
302         Return -1 on failure.
303         """
304         return 0
305 
306     def rindex(self, sub, start=None, end=None): # real signature unknown; restored from __doc__
307         """
308         S.rindex(sub[, start[, end]]) -> int
309         
310         Like S.rfind() but raise ValueError when the substring is not found.
311         """
312         return 0
313 
314     def rjust(self, width, fillchar=None): # real signature unknown; restored from __doc__
315         """
316         S.rjust(width[, fillchar]) -> str
317         
318         Return S right-justified in a string of length width. Padding is
319         done using the specified fill character (default is a space).
320         """
321         return ""
322 
323     def rpartition(self, sep): # real signature unknown; restored from __doc__
324         """
325         S.rpartition(sep) -> (head, sep, tail)
326         
327         Search for the separator sep in S, starting at the end of S, and return
328         the part before it, the separator itself, and the part after it.  If the
329         separator is not found, return two empty strings and S.
330         """
331         pass
332 
333     def rsplit(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
334         """
335         S.rsplit(sep=None, maxsplit=-1) -> list of strings
336         
337         Return a list of the words in S, using sep as the
338         delimiter string, starting at the end of the string and
339         working to the front.  If maxsplit is given, at most maxsplit
340         splits are done. If sep is not specified, any whitespace string
341         is a separator.
342         """
343         return []
344 
345     def rstrip(self, chars=None): # real signature unknown; restored from __doc__
346         """
347         S.rstrip([chars]) -> str
348         
349         Return a copy of the string S with trailing whitespace removed.
350         If chars is given and not None, remove characters in chars instead.
351         """
352         return ""
353 
354     def split(self, sep=None, maxsplit=-1): # real signature unknown; restored from __doc__
355         """
356         S.split(sep=None, maxsplit=-1) -> list of strings
357         
358         Return a list of the words in S, using sep as the
359         delimiter string.  If maxsplit is given, at most maxsplit
360         splits are done. If sep is not specified or is None, any
361         whitespace string is a separator and empty strings are
362         removed from the result.
363         """
364         return []
365 
366     def splitlines(self, keepends=None): # real signature unknown; restored from __doc__
367         """
368         S.splitlines([keepends]) -> list of strings
369         
370         Return a list of the lines in S, breaking at line boundaries.
371         Line breaks are not included in the resulting list unless keepends
372         is given and true.
373         """
374         return []
375 
376     def startswith(self, prefix, start=None, end=None): # real signature unknown; restored from __doc__
377         """
378         S.startswith(prefix[, start[, end]]) -> bool
379         
380         Return True if S starts with the specified prefix, False otherwise.
381         With optional start, test S beginning at that position.
382         With optional end, stop comparing S at that position.
383         prefix can also be a tuple of strings to try.
384         """
385         return False
386 
387     def strip(self, chars=None): # real signature unknown; restored from __doc__
388         """
389         S.strip([chars]) -> str
390         
391         Return a copy of the string S with leading and trailing
392         whitespace removed.
393         If chars is given and not None, remove characters in chars instead.
394         """
395         return ""
396 
397     def swapcase(self): # real signature unknown; restored from __doc__
398         """
399         S.swapcase() -> str
400         
401         Return a copy of S with uppercase characters converted to lowercase
402         and vice versa.
403         """
404         return ""
405 
406     def title(self): # real signature unknown; restored from __doc__
407         """
408         S.title() -> str
409         
410         Return a titlecased version of S, i.e. words start with title case
411         characters, all remaining cased characters have lower case.
412         """
413         return ""
414 
415     def translate(self, table): # real signature unknown; restored from __doc__
416         """
417         S.translate(table) -> str
418         
419         Return a copy of the string S in which each character has been mapped
420         through the given translation table. The table must implement
421         lookup/indexing via __getitem__, for instance a dictionary or list,
422         mapping Unicode ordinals to Unicode ordinals, strings, or None. If
423         this operation raises LookupError, the character is left untouched.
424         Characters mapped to None are deleted.
425         """
426         return ""
427 
428     def upper(self): # real signature unknown; restored from __doc__
429         """
430         S.upper() -> str
431         
432         Return a copy of S converted to uppercase.
433         """
434         return ""
435 
436     def zfill(self, width): # real signature unknown; restored from __doc__
437         """
438         S.zfill(width) -> str
439         
440         Pad a numeric string S with zeros on the left, to fill a field
441         of the specified width. The string S is never truncated.
442         """
443         return ""
444 
445     def __add__(self, *args, **kwargs): # real signature unknown
446         """ Return self+value. """
447         pass
448 
449     def __contains__(self, *args, **kwargs): # real signature unknown
450         """ Return key in self. """
451         pass
452 
453     def __eq__(self, *args, **kwargs): # real signature unknown
454         """ Return self==value. """
455         pass
456 
457     def __format__(self, format_spec): # real signature unknown; restored from __doc__
458         """
459         S.__format__(format_spec) -> str
460         
461         Return a formatted version of S as described by format_spec.
462         """
463         return ""
464 
465     def __getattribute__(self, *args, **kwargs): # real signature unknown
466         """ Return getattr(self, name). """
467         pass
468 
469     def __getitem__(self, *args, **kwargs): # real signature unknown
470         """ Return self[key]. """
471         pass
472 
473     def __getnewargs__(self, *args, **kwargs): # real signature unknown
474         pass
475 
476     def __ge__(self, *args, **kwargs): # real signature unknown
477         """ Return self>=value. """
478         pass
479 
480     def __gt__(self, *args, **kwargs): # real signature unknown
481         """ Return self>value. """
482         pass
483 
484     def __hash__(self, *args, **kwargs): # real signature unknown
485         """ Return hash(self). """
486         pass
487 
488     def __init__(self, value=http://www.mamicode.com/‘‘, encoding=None, errors=strict): # known special case of str.__init__
489         """
490         str(object=‘‘) -> str
491         str(bytes_or_buffer[, encoding[, errors]]) -> str
492         
493         Create a new string object from the given object. If encoding or
494         errors is specified, then the object must expose a data buffer
495         that will be decoded using the given encoding and error handler.
496         Otherwise, returns the result of object.__str__() (if defined)
497         or repr(object).
498         encoding defaults to sys.getdefaultencoding().
499         errors defaults to ‘strict‘.
500         # (copied from class doc)
501         """
502         pass
503 
504     def __iter__(self, *args, **kwargs): # real signature unknown
505         """ Implement iter(self). """
506         pass
507 
508     def __len__(self, *args, **kwargs): # real signature unknown
509         """ Return len(self). """
510         pass
511 
512     def __le__(self, *args, **kwargs): # real signature unknown
513         """ Return self<=value. """
514         pass
515 
516     def __lt__(self, *args, **kwargs): # real signature unknown
517         """ Return self<value. """
518         pass
519 
520     def __mod__(self, *args, **kwargs): # real signature unknown
521         """ Return self%value. """
522         pass
523 
524     def __mul__(self, *args, **kwargs): # real signature unknown
525         """ Return self*value.n """
526         pass
527 
528     @staticmethod # known case of __new__
529     def __new__(*args, **kwargs): # real signature unknown
530         """ Create and return a new object.  See help(type) for accurate signature. """
531         pass
532 
533     def __ne__(self, *args, **kwargs): # real signature unknown
534         """ Return self!=value. """
535         pass
536 
537     def __repr__(self, *args, **kwargs): # real signature unknown
538         """ Return repr(self). """
539         pass
540 
541     def __rmod__(self, *args, **kwargs): # real signature unknown
542         """ Return value%self. """
543         pass
544 
545     def __rmul__(self, *args, **kwargs): # real signature unknown
546         """ Return self*value. """
547         pass
548 
549     def __sizeof__(self): # real signature unknown; restored from __doc__
550         """ S.__sizeof__() -> size of S in memory, in bytes """
551         pass
552 
553     def __str__(self, *args, **kwargs): # real signature unknown
554         """ Return str(self). """
555         pass
556 
557 
558 class super(object):
559     """
560     super() -> same as super(__class__, <first argument>)
561     super(type) -> unbound super object
562     super(type, obj) -> bound super object; requires isinstance(obj, type)
563     super(type, type2) -> bound super object; requires issubclass(type2, type)
564     Typical use to call a cooperative superclass method:
565     class C(B):
566         def meth(self, arg):
567             super().meth(arg)
568     This works for class methods too:
569     class C(B):
570         @classmethod
571         def cmeth(cls, arg):
572             super().cmeth(arg)
573     """
574     def __getattribute__(self, *args, **kwargs): # real signature unknown
575         """ Return getattr(self, name). """
576         pass
577 
578     def __get__(self, *args, **kwargs): # real signature unknown
579         """ Return an attribute of instance, which is of type owner. """
580         pass
581 
582     def __init__(self, type1=None, type2=None): # known special case of super.__init__
583         """
584         super() -> same as super(__class__, <first argument>)
585         super(type) -> unbound super object
586         super(type, obj) -> bound super object; requires isinstance(obj, type)
587         super(type, type2) -> bound super object; requires issubclass(type2, type)
588         Typical use to call a cooperative superclass method:
589         class C(B):
590             def meth(self, arg):
591                 super().meth(arg)
592         This works for class methods too:
593         class C(B):
594             @classmethod
595             def cmeth(cls, arg):
596                 super().cmeth(arg)
597         
598         # (copied from class doc)
599         """
600         pass
601 
602     @staticmethod # known case of __new__
603     def __new__(*args, **kwargs): # real signature unknown
604         """ Create and return a new object.  See help(type) for accurate signature. """
605         pass
606 
607     def __repr__(self, *args, **kwargs): # real signature unknown
608         """ Return repr(self). """
609         pass
610 
611     __self_class__ = property(lambda self: type(object))
612     """the type of the instance invoking super(); may be None
613 
614     :type: type
615     """
616 
617     __self__ = property(lambda self: type(object))
618     """the instance invoking super(); may be None
619 
620     :type: type
621     """
622 
623     __thisclass__ = property(lambda self: type(object))
624     """the class invoking super()
625 
626     :type: type
627     """
628 
629 
630 
631 class SyntaxWarning(Warning):
632     """ Base class for warnings about dubious syntax. """
633     def __init__(self, *args, **kwargs): # real signature unknown
634         pass
635 
636     @staticmethod # known case of __new__
637     def __new__(*args, **kwargs): # real signature unknown
638         """ Create and return a new object.  See help(type) for accurate signature. """
639         pass
640 
641 
642 class SystemError(Exception):
643     """
644     Internal error in the Python interpreter.
645     
646     Please report this to the Python maintainer, along with the traceback,
647     the Python version, and the hardware/OS platform and version.
648     """
649     def __init__(self, *args, **kwargs): # real signature unknown
650         pass
651 
652     @staticmethod # known case of __new__
653     def __new__(*args, **kwargs): # real signature unknown
654         """ Create and return a new object.  See help(type) for accurate signature. """
655         pass
656 
657 
658 class SystemExit(BaseException):
659     """ Request to exit from the interpreter. """
660     def __init__(self, *args, **kwargs): # real signature unknown
661         pass
662 
663     code = property(lambda self: object(), lambda self, v: None, lambda self: None)  # default
664     """exception code"""
665 
666 
667 
668 class TabError(IndentationError):
669     """ Improper mixture of spaces and tabs. """
670     def __init__(self, *args, **kwargs): # real signature unknown
671         pass
672 
673 
674 class TimeoutError(OSError):
675     """ Timeout expired. """
676     def __init__(self, *args, **kwargs): # real signature unknown
677         pass
字符串的其他方法

 

##startswith,endswith
name = alex_SB
print(name.startswith(a))
print(name.endswith(SB))


##repalce
name = alex say: i have one tesla,my name is alex
print(name.replace(alex,SB))
print(name.replace(alex,SB,1))#指定替换几次

##format(由字符串本身提供的)
res = {}{}{}.format(egon,18,male)
res = {1}{0}{1}.format(egon,18,male)##根据索引来格式化
res = {name}{age}{sex}.format(sex=male,name = egon,age = 18)##根据指定的名称来替换


##判断是否是数字
num = 123
print(num.isdigit())
oldboy_age = 73
while True:
    age = input(>>: ).strip()
    if len(age) == 0:continue
    if age.isdigit():
        age = int(age)
        print(age,int(age))

##字符串其他需要了解的方法

name = egon
print(name.find(o))##没有时,显示-1,不会报错
print(name.index(o))##没有时会报错
print(name.count(o))##计数

#join
l = [egon,say,hello,world]
print(:.join(l))#按照冒号作分隔符,列表内容必须是字符串,相同内容也可以

#center
name = egon
print(name.center(30,*))##填充字符,指定宽度为30
print(name.ljust(30,*))##左边对齐,右边填充字符
print(name.zfill(30))#右对齐,不够用零填充

#expandtabs通常制表符指定的宽度为4,可以改变制表符指定的宽度
name = egon\thello
print(name.expandtabs(1))

##判断字母数字
name = egon123
print(name.isalnum())#字符串由字母和数字组成
print(name.isalpha())##判断字符串是否全部是由字母组成的
print(name.isdigit())#判断字符串是否全部由数字组成的

(三)列表
列表的常用操作

索引

切片

追加

删除

长度

循环

包含in

##pop()弹出操作
my_girl_friends = [wupeiqi,alex,yuanhao,4,10,30]
my_girl_friends.pop()##默认弹出的是最后一个元素,但是可以指定弹出元素的位置,指定位置参数
my_girl_friends.remove(wupeiqi)##是按照值弹出的

##成员运算
print(wupeiqi in my_girl_friends)

#追加运算
print(my_girl_friends.append(oldboy))#追加一个元素到最后一个位置
print(my_girl_friends.extend([oldboy1,oldboy2]))##可以追加列表



##可以指定元素的起始序号
li= [11,22,33]
for k,v in enumerate(li,1)
    print(k,v)

 (四)元组

元组的常用操作

索引

切片

循环

长度

包含in

##元组
tu = (11,22,33,11)
print(tu.count(11))##计数
print(tu.index(1))##索引

(五)字典

##字典
dic = {k1:v1,k2:v2}
print(dic.clear())#清空
print(dic.copy())#浅拷贝
print(dic.get(k1))#根据key获取指定的value
print(dic.pop(k1))#获取并删除对应的value
print(dic.popitem())#随机删除一个键值对
dic.setdefault(k3,v3)
print(dic)#增加,如果存在不做任何操作
dic.update({k3:v3,k1:v4})#批量增加或者修改

##生成一个字典
dic = dic.fromkeys([k1,k2,k3],123)
print(dic)

(六)集合

可认为是不可重复的列表,集合是可变类型

##集合
se1 = {alex,eric,tony}
se2 = {alex,egon,dreamki}
#交,并,补,差
print(se1 & se2)#交运算
print(se1 | se2)#并运算
print(se1 ^ se2)#补运算
print(se1 - se2)#差运算

 

 

 

 

 

 

Python基本数据类型