首页 新闻 会员 周边

Python3.8 dir(str)

0
悬赏园豆:5 [已解决问题] 解决于 2020-08-15 18:42

dir(str)
['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(str)显示str的内置方法,请问capitalize开始是方法,前面的例如__add__,是什么意思.....

王钻风的主页 王钻风 | 初学一级 | 园豆:185
提问于:2020-08-13 07:59
< >
分享
最佳答案
0

应该也是方法,前面后面都有双下划线表示这个方法是一个特殊方法,这种命名方式提醒程序员最好不要直接调用。详见这里:Python中下划线的5种含义

收获园豆:5
会长 | 专家六级 |园豆:12401 | 2020-08-13 09:26

谢谢回答

王钻风 | 园豆:185 (初学一级) | 2020-08-15 18:41
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册