Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
cls_var und cls_method
#python 3.6.9 print ("Hello, world!") class P: cls_var = 'cls_var noch nicht initialisiert' def __init__(self): self.x=0 self.y=0 @classmethod def cls_method_init(cls): cls.cls_var = 'cls_var initialisiert in cls_method' @classmethod def cls_method_default(cls): cls.cls_var = 'cls_var noch nicht initialisiert' def inc_x(self): self.x = self.x+1 def dec_x(self): self.x = self.x-1 def inc_y(self): self.y = self.y+1 def dec_y(self): self.y = self.y-1 def __str__(self): return f'({self.x}, {self.y}, {P.cls_var})' P.cls_method_init() p1 = P() print(f'p1: {p1}') p1.inc_x() print(f'p1: {p1}') p1.inc_y() print(f'p1: {p1}') P.cls_method_default() print(f'p1: {p1}') p1.dec_y() print(f'p1: {p1}') p1.dec_x() print(f'p1: {p1}')
run
|
edit
|
history
|
help
0
Lab_I_1_25_11_2020
My cousin asked for this will never forgive her
hi
alternative dict.get (faster)
Happy new year!
Name of students
Emails_Python
BasicFunctionsPrograms,py
PySlots2
test3.py