zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    Azure Queues and Service Bus Queues
    同步消息队列模型
    ADO.NET Asynchronous Programming
    js中cookie
    字符串格式化命令 sprintf
    JS的Touch事件们,触屏时的js事件
    imac上php环境php+apache+mysql
    日历js插件
    html_entity_decode 函数 编辑器输出之显示含html为转义 thinkphp
    thinkphp自定义权限管理之名称判断
  • 原文地址:https://www.cnblogs.com/jason2018524/p/14106277.html
Copyright © 2011-2022 走看看