print('10/3 = ' 10/3)
will directly report a syntax error.
If it is Java language, it will print out10/3 = 3
. How can I achieve such printing through Python?
I searched some information, and they all said that Python only supports the same type, such asprint(True False)
.
How to implement the appeal function?
Yes, but Python is a strongly typed language and does not like automatic type conversion. The fact that you can use
'10/3 = ' + str(10/3)
这样子显式转换类型。另外 Python 能够True + False
is a legacy issue because adding bool values doesn't make sense.Of course, Python has many good ways to handle string concatenation. The following is the sequence of historical development:
PS: To "appeal", you have to fight a lawsuit first, and then if you are dissatisfied with the verdict, you can file an "appeal".
class myString(str):
ex=myString('10/3')
print(ex+10/3)
I hope it won’t cause any confusion for you; if it’s ruby, you don’t need to customize the subclass of str, just modify it directly on str, because it’s all “open”, although I’m not very good at ruby