zoukankan      html  css  js  c++  java
  • [Python] Find available methods and help in REPL

    For example you want to know what methods are available in Python for String, you can do :

    dir("xxx")

    Output:

    >>> dir("string")
    ['__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', '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']

    Now for example, we want to see How to use 'swapcase' method:

    help("foo".swapcase)

    It will show example and description about the method, which is very useful

  • 相关阅读:
    python数据结构树和二叉树简介
    python双向链表的实现
    Python单向链表的实现
    栈和队列数据结构的基本概念及其相关的Python实现
    模型融合目录
    算法汇总目录
    一个完整的机器学习目录
    python基础-面向对象opp
    Python random模块
    python-字符串前面添加u,r,b的含义
  • 原文地址:https://www.cnblogs.com/Answer1215/p/8016061.html
Copyright © 2011-2022 走看看