TI/Skrypty z zajęć/k7: Różnice pomiędzy wersjami
Z Brain-wiki
(Utworzono nową stronę "<source lang="python"> aa </source>") |
|||
Linia 1: | Linia 1: | ||
<source lang="python"> | <source lang="python"> | ||
− | + | # -*- coding: utf-8 -*- | |
+ | """ | ||
+ | Created on Tue Jun 2 12:30:34 2020 | ||
+ | |||
+ | @author: Tomek | ||
+ | """ | ||
+ | |||
+ | class Punkt(): | ||
+ | __ile_nas = 0 | ||
+ | |||
+ | @staticmethod | ||
+ | def kwadratowa(x): | ||
+ | return x**2 | ||
+ | |||
+ | @classmethod | ||
+ | def ile_nas(cls): | ||
+ | return cls.__ile_nas | ||
+ | |||
+ | def __init__(self, x, y): | ||
+ | self.__x = x | ||
+ | self.__y = y | ||
+ | Punkt.__ile_nas += 1 | ||
+ | |||
+ | def __del__(self): | ||
+ | Punkt.__ile_nas -=1 | ||
+ | |||
+ | def getX(self): return self.__x | ||
+ | def getY(self): return self.__y | ||
+ | |||
+ | p1 = Punkt(1,1) | ||
+ | p1 = Punkt(1,4) | ||
+ | p2 = Punkt(5,4) | ||
+ | p3 = Punkt(5,1) | ||
+ | |||
</source> | </source> |
Aktualna wersja na dzień 13:25, 2 cze 2020
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 2 12:30:34 2020
@author: Tomek
"""
class Punkt():
__ile_nas = 0
@staticmethod
def kwadratowa(x):
return x**2
@classmethod
def ile_nas(cls):
return cls.__ile_nas
def __init__(self, x, y):
self.__x = x
self.__y = y
Punkt.__ile_nas += 1
def __del__(self):
Punkt.__ile_nas -=1
def getX(self): return self.__x
def getY(self): return self.__y
p1 = Punkt(1,1)
p1 = Punkt(1,4)
p2 = Punkt(5,4)
p3 = Punkt(5,1)