class dönüştürme
This commit is contained in:
parent
8099c2b8b6
commit
c94859813f
29
python-temel/class.donusturme.py
Normal file
29
python-temel/class.donusturme.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
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)
|
Loading…
Reference in New Issue
Block a user