zoukankan      html  css  js  c++  java
  • python之路(1)数据类型

    目录

    整型(int)

    1. 将字符串转换成整型
    num = "123"
    v = int(num)
    

       2. 将字符串按进制位转换成整型

    num = "123"
    v = int(num,base=8)

       3. 输出将当前整数的二进制位数

    num = 10
    v = num.bit_length()

    布尔值(bool)  

      true和false

      0和1

    字符串(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, *args, **kwargs):  # real signature unknown
        """首字母大写"""
        """
        Return a capitalized version of the string.
    
        More specifically, make the first character have upper case and the rest lower
        case.
        """
        pass
    
    
    def center(self, *args, **kwargs):  # real signature unknown
        """ 指定宽度,将字符填在中间,两边默认填充空格"""
        """
        Return a centered string of length width.
    
        Padding is done using the specified fill character (default is a space).
        """
        pass
    
    
    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, *args, **kwargs):  # real signature unknown
        """ url编码"""
        """
        Encode the string using the codec registered for encoding.
    
          encoding
            The encoding in which to encode the string.
          errors
            The error handling scheme to use for encoding errors.
            The 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.
        """
        pass
    
    
    def endswith(self, suffix, start=None, end=None):  # real signature unknown; restored from __doc__
        """最后子字符串是否匹配指定子字符串,相同返回true,不同返回false,可以指定起始和结束位置"""
        """
        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, *args, **kwargs):  # real signature unknown
        """将字符串中的tab符(	)转换8个空格,依次取8个字符,直到匹配到tab符,缺几个空格补几个空格"""
        """
        Return a copy where all tab characters are expanded using spaces.
    
        If tabsize is not given, a tab size of 8 characters is assumed.
        """
        pass
    
    
    def find(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """查找子字符串最低索引,找到返回索引,否则返回-1,可以指定起始和结束位置"""
        """
        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 rfind(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """从右边查找子字符串最低索引,找到返回索引,否则返回-1,可以指定起始和结束位置"""
        """ """
        """
        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 format(self, *args, **kwargs):  # known special case of str.format
        """替换以{""}表示的占位符,参数使用字符串列表和key=value的形式"""
        """
        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__
        """替换以{""}表示的占位符,参数使用z字典"""
        """
        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
    
        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.
    
        Raises ValueError when the substring is not found.
        """
        return 0
    
    
    def rindex(self, sub, start=None, end=None):  # real signature unknown; restored from __doc__
        """从右边查找子字符串的最低索引,找到返回索引,否则报异常信息,可以指定起始和结束位置"""
        """
        S.rindex(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.
    
        Raises ValueError when the substring is not found.
        """
        return 0
    
    
    def isalnum(self, *args, **kwargs):  # real signature unknown
        """判断是不是纯字母和数字,返回boolean值"""
        """
        Return True if the string is an alpha-numeric string, False otherwise.
    
        A string is alpha-numeric if all characters in the string are alpha-numeric and
        there is at least one character in the string.
        """
        pass
    
    
    def isalpha(self, *args, **kwargs):  # real signature unknown
        """判断是不是纯字母,返回boolean值"""
        """
        Return True if the string is an alphabetic string, False otherwise.
    
        A string is alphabetic if all characters in the string are alphabetic and there
        is at least one character in the string.
        """
        pass
    
    
    def isascii(self, *args, **kwargs):  # real signature unknown
        """判断是不是ascii值,返回boolean值"""
        """
        Return True if all characters in the string are ASCII, False otherwise.
    
        ASCII characters have code points in the range U+0000-U+007F.
        Empty string is ASCII too.
        """
        pass
    
    
    def isdecimal(self, *args, **kwargs):  # real signature unknown
        """判断是不是十进制数字符串,返回boolean值"""
        """
        Return True if the string is a decimal string, False otherwise.
    
        A string is a decimal string if all characters in the string are decimal and
        there is at least one character in the string.
        """
        pass
    
    
    def isdigit(self, *args, **kwargs):  # real signature unknown
        """判断是不是数字字符串,返回boolean值"""
        """
        Return True if the string is a digit string, False otherwise.
    
        A string is a digit string if all characters in the string are digits and there
        is at least one character in the string.
        """
        pass
    
    
    def isidentifier(self, *args, **kwargs):  # real signature unknown
        """判断是不是python标识符(字母,下划线和数字,不能以数字开头),返回boolean值"""
        """
        Return True if the string is a valid Python identifier, False otherwise.
    
        Use keyword.iskeyword() to test for reserved identifiers such as "def" and
        "class".
        """
        pass
    
    
    def islower(self, *args, **kwargs):  # real signature unknown
        """判断是不是小写,返回boolean值"""
        """
        Return True if the string is a lowercase string, False otherwise.
    
        A string is lowercase if all cased characters in the string are lowercase and
        there is at least one cased character in the string.
        """
        pass
    
    
    def isnumeric(self, *args, **kwargs):  # real signature unknown
        """判断是不是数字字符,返回boolean值,认识阿拉伯数字之外的数字字符"""
        """
        Return True if the string is a numeric string, False otherwise.
    
        A string is numeric if all characters in the string are numeric and there is at
        least one character in the string.
        """
        pass
    
    
    def isprintable(self, *args, **kwargs):  # real signature unknown
        """ 判断是否有转义字符存在,返回boolean值"""
        """
        Return True if the string is printable, False otherwise.
    
        A string is printable if all of its characters are considered printable in
        repr() or if it is empty.
        """
        pass
    
    
    def isspace(self, *args, **kwargs):  # real signature unknown
        """判断是不是空格,返回boolean值"""
        """
        Return True if the string is a whitespace string, False otherwise.
    
        A string is whitespace if all characters in the string are whitespace and there
        is at least one character in the string.
        """
        pass
    
    
    def istitle(self, *args, **kwargs):  # real signature unknown
        """判断是不是标题(每个单词首字母大写),返回boolean值"""
        """
        Return True if the string is a title-cased string, False otherwise.
    
        In a title-cased string, upper- and title-case characters may only
        follow uncased characters and lowercase characters only cased ones.
        """
        pass
    
    
    def isupper(self, *args, **kwargs):  # real signature unknown
        """判断是不是大写,返回boolean值"""
        """
        Return True if the string is an uppercase string, False otherwise.
    
        A string is uppercase if all cased characters in the string are uppercase and
        there is at least one cased character in the string.
        """
        pass
    
    
    def join(self, ab=None, pq=None, rs=None):  # real signature unknown; restored from __doc__
        """将字符填充到给定字符串的每个字符之间"""
        """
        Concatenate any number of strings.
    
        The string whose method is called is inserted in between each given string.
        The result is returned as a new string.
    
        Example: '.'.join(['ab', 'pq', 'rs']) -> 'ab.pq.rs'
        """
        pass
    
    
    def ljust(self, *args, **kwargs):  # real signature unknown
        """在字符串的右边填充字符"""
        """
        Return a left-justified string of length width.
    
        Padding is done using the specified fill character (default is a space).
        """
        pass
    
    
    def rjust(self, *args, **kwargs):  # real signature unknown
        """在字符串的左边填充字符"""
        """
        Return a right-justified string of length width.
    
        Padding is done using the specified fill character (default is a space).
        """
        pass
    
    
    def lower(self, *args, **kwargs):  # real signature unknown
        """字母小写"""
        """ Return a copy of the string converted to lowercase. """
        pass
    
    
    def upper(self, *args, **kwargs):  # real signature unknown
        """字母大写"""
        """ Return a copy of the string converted to uppercase. """
        pass
    
    
    def casefold(self, *args, **kwargs):    # real signature unknown
        """" 将大写转换成小写 适用其他国家的语法"""
        """ Return a version of the string suitable for caseless comparisons. """
        pass
    
    
    def lstrip(self, *args, **kwargs):  # real signature unknown
        """删除从左边匹配的字符串"""
        """
        Return a copy of the string with leading whitespace removed.
    
        If chars is given and not None, remove characters in chars instead.
        """
        pass
    
    
    def maketrans(self, *args, **kwargs):  # real signature unknown
        """设置字符的对应关系,与translate连用"""
        """
        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 translate(self, *args, **kwargs):  # real signature unknown
        """根据对应关系,翻译字符串"""
        """
        Replace each character in the string using the given translation table.
    
          table
            Translation table, which must be a mapping of Unicode ordinals to
            Unicode ordinals, strings, or None.
    
        The table must implement lookup/indexing via __getitem__, for instance a
        dictionary or list.  If this operation raises LookupError, the character is
        left untouched.  Characters mapped to None are deleted.
        """
        pass
    
    
    def partition(self, *args, **kwargs):  # real signature unknown
        """指定字符切割"""
        """
        Partition the string into three parts using the given separator.
    
        This will search for the separator in the string.  If the separator is found,
        returns a 3-tuple containing the part before the separator, the separator
        itself, and the part after it.
    
        If the separator is not found, returns a 3-tuple containing the original string
        and two empty strings.
        """
        pass
    
    
    def rpartition(self, *args, **kwargs):  # real signature unknown
        """从右边指定字符切割"""
        """
        Partition the string into three parts using the given separator.
    
        This will search for the separator in the string, starting at the end. If
        the separator is found, returns a 3-tuple containing the part before the
        separator, the separator itself, and the part after it.
    
        If the separator is not found, returns a 3-tuple containing two empty strings
        and the original string.
        """
        pass
    
    
    def replace(self, *args, **kwargs):  # real signature unknown
        """用新字符串,替换旧字符串,默认全部替换"""
        """
        Return a copy with all occurrences of substring old replaced by new.
    
          count
            Maximum number of occurrences to replace.
            -1 (the default value) means replace all occurrences.
    
        If the optional argument count is given, only the first count occurrences are
        replaced.
        """
        pass
    
    
    
    def rsplit(self, *args, **kwargs):  # real signature unknown
        """指定字符从右边分割字符串,可指定最大分割"""
        """
        Return a list of the words in the string, using sep as the delimiter string.
    
          sep
            The delimiter according which to split the string.
            None (the default value) means split according to any whitespace,
            and discard empty strings from the result.
          maxsplit
            Maximum number of splits to do.
            -1 (the default value) means no limit.
    
        Splits are done starting at the end of the string and working to the front.
        """
        pass
    
    
    def split(self, *args, **kwargs):  # real signature unknown
        """指定字符分割字符串,可指定最大分割"""
        """
        Return a list of the words in the string, using sep as the delimiter string.
    
          sep
            The delimiter according which to split the string.
            None (the default value) means split according to any whitespace,
            and discard empty strings from the result.
          maxsplit
            Maximum number of splits to do.
            -1 (the default value) means no limit.
        """
        pass
    
    
    def splitlines(self, *args, **kwargs):  # real signature unknown
        """根据换行(
    )分割,true指定保留换行,false不保留"""
        """
        Return a list of the lines in the string, breaking at line boundaries.
    
        Line breaks are not included in the resulting list unless keepends is given and
        true.
        """
        pass
    
    
    def startswith(self, prefix, start=None, end=None):  # real signature unknown; restored from __doc__
        """判断是不是指定字符串开头,指定起始和结束位置,返回Boolean值"""
        """
        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, *args, **kwargs):  # real signature unknown
        """删除左右两边匹配的字符串,默认去除回车和空格"""
        """
        Return a copy of the string with leading and trailing whitespace remove.
    
        If chars is given and not None, remove characters in chars instead.
        """
        pass
    
    
    def rstrip(self, *args, **kwargs):  # real signature unknown
        """删除从右边匹配的字符串"""
        """
        Return a copy of the string with trailing whitespace removed.
    
        If chars is given and not None, remove characters in chars instead.
        """
        pass
    
    
    def swapcase(self, *args, **kwargs):  # real signature unknown
        """大小写转换"""
        """ Convert uppercase characters to lowercase and lowercase characters to uppercase. """
        pass
    
    
    def title(self, *args, **kwargs):  # real signature unknown
        """每个单词开头大写"""
        """
        Return a version of the string where each word is titlecased.
    
        More specifically, words start with uppercased characters and all remaining
        cased characters have lower case.
        """
        pass
    
    
    def zfill(self, *args, **kwargs):  # real signature unknown
        """从左边填充0"""
        """
        Pad a numeric string with zeros on the left, to fill a field of the given width.
    
        The string is never truncated.
        """
        pass
    str_method

    列表(list)

        ['a','b','c','d']

       1. 切片

    test = ['a','b','c','d']
    v = test[0:3]
    View Code

       2. 删除

    del test[2]
    View Code

       3. 判断元素是否在列表中

    v = 'a' in test
    View Code

      4. 转换list的条件为可迭代

    v = list("abcdef")
    View Code

      list方法

    class list(object):
        """
        Built-in mutable sequence.
    
        If no argument is given, the constructor creates a new empty list.
        The argument must be an iterable if specified.
        """
    
        def append(self, *args, **kwargs):  # real signature unknown
            """在后面追加items"""
            """ Append object to the end of the list. """
            pass
    
        def clear(self, *args, **kwargs):  # real signature unknown
            """清空"""
            """ Remove all items from list. """
            pass
    
        def copy(self, *args, **kwargs):  # real signature unknown
            """复制"""
            """ Return a shallow copy of the list. """
            pass
    
        def count(self, *args, **kwargs):  # real signature unknown
            """返回值的出现次数"""
            """ Return number of occurrences of value. """
            pass
    
        def extend(self, *args, **kwargs):  # real signature unknown
            """通过附加iterable中的元素来扩展列表"""
            """ Extend list by appending elements from the iterable. """
            pass
    
        def index(self, *args, **kwargs):  # real signature unknown
            """返回找到第一个值的索引,没找到报错"""
            """
            Return first index of value.
    
            Raises ValueError if the value is not present.
            """
            pass
    
        def insert(self, *args, **kwargs):  # real signature unknown
            """插入指定位置元素"""
            """ Insert object before index. """
            pass
    
        def pop(self, *args, **kwargs):  # real signature unknown
            """删除指定索引的value,并返回value,不指定索引,默认删除最后"""
            """
            Remove and return item at index (default last).
    
            Raises IndexError if list is empty or index is out of range.
            """
            pass
    
        def remove(self, *args, **kwargs):  # real signature unknown
            """删除列表指定value,左边优先"""
            """
            Remove first occurrence of value.
    
            Raises ValueError if the value is not present.
            """
            pass
    
        def reverse(self, *args, **kwargs):  # real signature unknown
            """翻转列表的值"""
            """ Reverse *IN PLACE*. """
            pass
    
        def sort(self, *args, **kwargs):  # real signature unknown
            """排序"""
            """ Stable sort *IN PLACE*. """
            pass
    list_method

    元组(tuple)

      ('a','b','c','d')

      1. 元组不可修改

       tuple方法

    class tuple(object):
        """
        Built-in immutable sequence.
    
        If no argument is given, the constructor returns an empty tuple.
        If iterable is specified the tuple is initialized from iterable's items.
    
        If the argument is a tuple, the return value is the same object.
        """
    
        def count(self, *args, **kwargs):  # real signature unknown
            """返回值的出现次数"""
            """ Return number of occurrences of value. """
            pass
    
        def index(self, *args, **kwargs):  # real signature unknown
            """返回找到第一个值的索引,没找到报错"""
            """
            Return first index of value.
    
            Raises ValueError if the value is not present.
            """
            pass
    tuple_method

    字典(dict)

      {  ‘a’:111, 'b':111, 'c':111, 'd':111 }

      dlct的方法

    class dict(object):
        """
        dict() -> new empty dictionary
        dict(mapping) -> new dictionary initialized from a mapping object's
            (key, value) pairs
        dict(iterable) -> new dictionary initialized as if via:
            d = {}
            for k, v in iterable:
                d[k] = v
        dict(**kwargs) -> new dictionary initialized with the name=value pairs
            in the keyword argument list.  For example:  dict(one=1, two=2)
        """
    
        def clear(self):  # real signature unknown; restored from __doc__
            """清空"""
            """ D.clear() -> None.  Remove all items from D. """
            pass
    
        def copy(self):  # real signature unknown; restored from __doc__
            """拷贝"""
            """ D.copy() -> a shallow copy of D """
            pass
    
        @staticmethod  # known case静态方法
        def fromkeys(*args, **kwargs):  # real signature unknown
            """使用来自iterable和值设置为value的键创建一个新字典"""
            """ Create a new dictionary with keys from iterable and values set to value. """
            pass
    
        def get(self, *args, **kwargs):  # real signature unknown
            """如果key在字典中,则返回key的值,否则返回default。"""
            """ Return the value for key if key is in the dictionary, else default. """
            pass
    
        def items(self):  # real signature unknown; restored from __doc__
            """获取字典里所有的键值对"""
            """"""
            """ D.items() -> a set-like object providing a view on D's items """
            pass
    
        def keys(self):  # real signature unknown; restored from __doc__
            """获取字典里所有的key"""
            """ D.keys() -> a set-like object providing a view on D's keys """
            pass
    
        def pop(self, k, d=None):  # real signature unknown; restored from __doc__
            """删除指点key的值,并返回value,如果key没找到,返回默认值"""
            """
            D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
            If key is not found, d is returned if given, otherwise KeyError is raised
            """
            pass
    
        def popitem(self):  # real signature unknown; restored from __doc__
            """删除键值对,并返回键值对"""
            """
            D.popitem() -> (k, v), remove and return some (key, value) pair as a
            2-tuple; but raise KeyError if D is empty.
            """
            pass
    
        def setdefault(self, *args, **kwargs):  # real signature unknown
            """如果键不在字典中,则插入值为default的值。
                如果key在字典中,则返回key的值,否则返回default。"""
            """
            Insert key with a value of default if key is not in the dictionary.
    
            Return the value for key if key is in the dictionary, else default.
            """
            pass
    
        def update(self, E=None, **F):  # known special case of dict.update
            """更新字典,参数可以是字典和‘key=value,key2=value2...’"""
            """
            D.update([E, ]**F) -> None.  Update D from dict/iterable E and F.
            If E is present and has a .keys() method, then does:  for k in E: D[k] = E[k]
            If E is present and lacks a .keys() method, then does:  for k, v in E: D[k] = v
            In either case, this is followed by: for k in F:  D[k] = F[k]
            """
            pass
    
        def values(self):  # real signature unknown; restored from __doc__
            """获得字典的values"""
            """ D.values() -> an object providing a view on D's values """
            pass
    dict_method
  • 相关阅读:
    ci 框架 报错级别 调整
    首页流氓广告的一种实现方法
    php中实现中文字符串的反转
    vmware 1021 错误解决 win7 64位
    isset 判断为POST信息是否为空 (笔记,持续更新)
    windows 下 ci 框架 命令行模式(cli)的使用
    ci 框架 excel 上传失败的处理
    php 日期处理(不断更新)
    svn的本地密码文件处理
    rpmdb open failed 的解决办法
  • 原文地址:https://www.cnblogs.com/shuzhixia/p/9735556.html
Copyright © 2011-2022 走看看