def __special__(self):
dostuff()
class strnum:
"""A class designed to show overloading operators in Python. This class is basic and is for holding strings that can be mixed with integers. These are not all the special functions, just the most important ones."""
def __init__(self, string):
int(string) # Just a test to see if string is a number.
string[0] # A test to see if it is a string with a length <= 1
self.string = string
def __add__(self, other):
"""This changes the addition + operator"""
return int(self.string) + int(other)
def __div__(self, other):
"""This changes the division / operator"""
return int(self.string) / int(other)
def __mul__(self, other):
"""This changes the multiplication * operator"""
return int(self.string) * int(other)
def __pow__(self, other):
"""This changes the exponent ** operator"""
return int(self.string) ** int(other)
def __str__(self):
"""This changes what appears when this object is printed"""
return self.string
def __sub__(self, other):
"""This changes the subtraction - operator"""
return int(self.string) - int(other)
Copyright © 2026, NextGenUpdate.
All Rights Reserved.