扫码关注官方订阅号
认证0级讲师
str.center('a', 3)和'a'.center(3)作用是一样的
str.center('a', 3)
'a'.center(3)
stackoverflow上的这个回答非常棒:
stackoverflow
http://stackoverflow.com/questions/1180303/static-vs-instance-methods-of-str-in-python
原理:
class C: def method(self, arg): print "In C.method, with", arg o = C() o.method(1) C.method(o, 1) # Prints: # In C.method, with 1 # In C.method, with 1
o.method(1) 可以看作是 C.method(o, 1)的简写。
o.method(1)
C.method(o, 1)
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
str.center('a', 3)和'a'.center(3)作用是一样的stackoverflow上的这个回答非常棒:http://stackoverflow.com/questions/1180303/static-vs-instance-methods-of-str-in-python
原理:
o.method(1)可以看作是C.method(o, 1)的简写。