1.绝对值
>>> age = -18 >>> age.__abs__() 18 >>> abs(age) 18
2.相加
>>> age = -18 >>> age.__add__(100) 82 >>> -18+100 82
3.商余数
>>> all_item = 95 >>> pager = 10 >>> result = all_item.__divmod__(pager) >>> print(result) (9, 5) #将商和余数以元组的格式显示,95//10 >>> age = 5 >>> result = age.__rdivmod__(2) >>> print(result) (0, 2) #2//5
4.相等
age = 18 result = age.__eq__(19) print(result)
5.浮点数转换
>>> age = 19 >>> type(age) <type ‘int‘> >>> result = age.__float__() >>> type(result) <type ‘float‘>
6.__floordiv__
>>> age = 5 >>> result = age.__floordiv__(6) >>> print(result) 0 >>> result = age.__floordiv__(2) >>> print(result) 2
时间: 2024-10-28 09:13:38