• Python有用的工具


    1、type:可用来确定对象属于哪种数据类型

    type("123456")

     结果:<class 'str'>

    type([123456,22])

    结果:<class 'list'>

    2、dir:可列出指定类型内置的方法与属性列表

    # 查看字符串内置的方法与属性列表
    type("123456")

    结果:

    ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

    # 查看列表内置的方法与属性列表
    dir(["abc"]

    结果:

    ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']

    3、help:获取指定对象、方法、或模块的帮助文档信息

    # 查看split方法的帮助文档,方法名不需要加括号
    help(" ".split)

    结果:

    Help on built-in function split:

    split(sep=None, maxsplit=-1) method of builtins.str instance
      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.

  • 相关阅读:
    docker 创建本地镜像服务器
    14.3.5.2 Deadlock Detection and Rollback 死锁检测和回滚:
    14.3.5.1 An InnoDB Deadlock Example
    14.3.4 Phantom Rows 幻影行
    14.3.4 Phantom Rows 幻影行
    14.3.3 Locks Set by Different SQL Statements in InnoDB 不同的SQL语句在InnoDB里的锁设置
    Mysql rr和rc隔离
    RR模式下的事务隔离
    RR模式下的事务隔离
    Maven学习总结(6)——Maven与Eclipse整合
  • 原文地址:https://www.cnblogs.com/jason2018524/p/14106277.html
Copyright © 2020-2023  润新知