python-CSD-kursu/python-temel/class.donusturme.py

30 lines
415 B
Python
Raw Normal View History

2023-08-03 15:57:42 +00:00
class Number:
def __init__(self, val):
self.val = val
def __int__(self):
return int(self.val)
def __float__(self):
return float(self.val)
def __bool__(self):
return bool(self.val)
def __complex__(self):
return complex(self.val)
n = Number(10)
val = int(n)
print(val)
val = float(n)
print(val)
val = bool(n)
print(val)
val = complex(n)
print(val)