Klasse oder statische Methode - Python

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Klasse oder statische Methode - Python

by Guest » 24 Dec 2024, 21:17

Ich möchte in meinem Fall verstehen, ob ich eine statische oder eine Klassenmethode verwenden soll.
Die Idee: Ich bearbeite keine Klassenvariable, sondern verwende diese Variable.
Beispiel 1:

Code: Select all

class RandClass():
static_variable = "some rand value to static variable"

@classmethod
def func_that_return_string_contain_static_variable(cls):
return "some rand string" + cls.static_variable
Beispiel2:

Code: Select all

class RandClass():
static_variable = "some rand value to static variable"

@staticmethod
def func_that_return_string_contain_static_variable():
return "some rand string" + RandClass.static_variable
Was ist die beste Vorgehensweise?

Top