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.

  • 相关阅读:
    keras模块学习之泛型模型学习笔记
    keras模块学习之Sequential模型学习笔记
    keras模块学习之model层【重点学习】
    keras模块学习之层(layer)的使用-笔记
    keras模块学习之-参数初始化与对象调用-笔记
    keras模块学习之-激活函数(activations)--笔记
    keras模块学习之-目标函数(objectives)笔记
    业务驱动下的项目管理实践
    关于跨团队合作的一些思考
    当我们谈论计划时我们在谈论什么
  • 原文地址:https://www.cnblogs.com/jason2018524/p/14106277.html
Copyright © 2011-2022 走看看