zoukankan      html  css  js  c++  java
  • 内置函数dir

    描述:

    dir内置函数的作用:列出对象的所有属性和可用的方法

    示例代码:

    s = 'hello'
    print(dir(s))  # 得到字符串的所有可用方法
    
    """
        执行结果:
        [
        '__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'
        ]
    """
    View Code
  • 相关阅读:
    数组的反转和二维数组
    初识数组
    Python学习笔记-Day8
    Python学习笔记-Day7
    Python学习笔记-Day6
    Python学习笔记-Day5
    Python学习笔记-Day4
    Python学习笔记-Day3
    Python学习笔记-Day2
    Python学习笔记-Day1
  • 原文地址:https://www.cnblogs.com/yujiemeigui/p/14611307.html
Copyright © 2011-2022 走看看