class dönüştürme

This commit is contained in:
Mert Gör ☭ 2023-08-03 18:57:42 +03:00
parent 8099c2b8b6
commit c94859813f
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
1 changed files with 29 additions and 0 deletions

View 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)