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.

  • 相关阅读:
    保险实战
    单片机的应用(位操作)
    显示转换(类型转换)
    游泳池的容量
    消失的重量(隐式变换)
    物品交换(变量)
    物品的存放(变量)
    输出变量的界值(int、float、long.....)
    在屏幕上输出内容
    C#笔记
  • 原文地址:https://www.cnblogs.com/jason2018524/p/14106277.html
Copyright © 2011-2022 走看看