码迷,mamicode.com
首页 > 编程语言 > 详细

Python(88)_双下划线方法

时间:2019-03-12 14:12:08      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:int   等等   code   coding   交集   划线   imp   []   pre   

1、双下划线方法

#-*-coding:utf-8-*-
import os
import time
‘‘‘
迭代器
‘‘‘
print(dir([]))  # 告诉我列表拥有的所有方法
print(dir({}))
print(dir(‘‘))

‘‘‘
求共有方法,集合求交集
‘‘‘
ret = set(dir([]))&set(dir({}))&set(dir(‘‘))&set(dir(range(10)))
print(ret)  #  __iter__ 

print([1].__add__([2]))
print([1]+[2])  # 这句话其实是内部调用上面的函数  1+2等等,都是调用双下方法

 

Python(88)_双下划线方法

标签:int   等等   code   coding   交集   划线   imp   []   pre   

原文地址:https://www.cnblogs.com/sunnybowen/p/10516161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!