lt;译文>Python中静态方法和类方法的区别是什么
1个回答
展开全部
问题:What
is
the
difference
between
a
static
method
and
class
method
in
Python?
Python中静态方法和类方法的区别是什么?
问题原文:
Python
has
two
decorators
@staticmethod
and
@classmethod.
Could
someone
one
explain
the
difference
between
the
two
or
point
me
to
a
source
where
it
is
documented?
When
should
the
staticmethod
decorator
be
used
over
the
classmethod
decorator?
问题译文:
Python有两种装饰器静态方法装饰器@staticmethod
和类方法装饰器@classmethod。谁能解释一下两者的区别或者给我指点点文档资料?什么时候该用静态方法装饰器或者类方法装饰器?
Answers:
1.Maybe
a
bit
of
example
code
will
help:
Notice
the
difference
in
the
call
signatures
of
foo,
class_foo
and
static_foo:
可能一点例子代码会有帮助:注意调用函数foo、class_foo、static_foo的写法上的区别
class
A
(
object
):
def
foo
(
self
,
x
):
print
"executing
foo(%s,%s)"
%(
self
,
x
)
@classmethod
def
class_foo
(
cls
,
x
):
print
"executing
class_foo(%s,%s)"
%(
cls
,
x
)
@staticmethod
def
static_foo
(
x
):
print
"executing
static_foo(%s)"
%
x
is
the
difference
between
a
static
method
and
class
method
in
Python?
Python中静态方法和类方法的区别是什么?
问题原文:
Python
has
two
decorators
@staticmethod
and
@classmethod.
Could
someone
one
explain
the
difference
between
the
two
or
point
me
to
a
source
where
it
is
documented?
When
should
the
staticmethod
decorator
be
used
over
the
classmethod
decorator?
问题译文:
Python有两种装饰器静态方法装饰器@staticmethod
和类方法装饰器@classmethod。谁能解释一下两者的区别或者给我指点点文档资料?什么时候该用静态方法装饰器或者类方法装饰器?
Answers:
1.Maybe
a
bit
of
example
code
will
help:
Notice
the
difference
in
the
call
signatures
of
foo,
class_foo
and
static_foo:
可能一点例子代码会有帮助:注意调用函数foo、class_foo、static_foo的写法上的区别
class
A
(
object
):
def
foo
(
self
,
x
):
"executing
foo(%s,%s)"
%(
self
,
x
)
@classmethod
def
class_foo
(
cls
,
x
):
"executing
class_foo(%s,%s)"
%(
cls
,
x
)
@staticmethod
def
static_foo
(
x
):
"executing
static_foo(%s)"
%
x
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询