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.

  • 相关阅读:
    简单的三级联动练习
    JavaScript中定时器的暂停和继续
    关于ajax网络请求的封装
    关于JS历史
    KVC中setValuesForKeysWithDictionary:
    collectionView 中cell间距设置建议
    iOS中你必须了解的多线程
    iOS中关于动态Tableview中的cell数据传输的多线程问题解决之拙见
    Touch
    Filemanager 的使用
  • 原文地址:https://www.cnblogs.com/jason2018524/p/14106277.html
Copyright © 2011-2022 走看看