+ 3
How to cast in python : 2
Hi I have a question on casting derived object to base class without loosing data. How to do this in python? I came from c++ background and this is feasible in C++ so checking about same in python . Is it possible or not? If yes, how. Refer code below. It has sample code and question also in comment section of code. https://sololearn.com/compiler-playground/cb1G9SPjxs85/?ref=app
12 Respuestas
+ 2
if you want to create a child class you need to type class Class_Name(Parent_Class_Name):
The new class will have the same functions
+ 2
The null value of the _a attribute for the display method of the inherited class is initially in the namespace of the base class. Whereas during its update
this space is changed to the local one of the instance itself. Therefore, you will not be able to see it by calling the display method on the base class.
In this case, I suggest using the data descriptor, for which the search for instances scans the chain of namespaces, giving them the highest priority.
https://sololearn.com/compiler-playground/cCvlV5tKdow9/?ref=app
+ 1
Modified title.
+ 1
Could you please elaborate on below🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦 ?
"if you want to create a child class you need to type class Class_Name(Parent_Class_Name):
The new class will have the same functions"
Does this mean inheritance is not needed and still I just get all methods of one class in other Class? If not, then what you wanted convey ? If yes, what's the way to do so.?
+ 1
Benoît Tagbino Je ne sais pas pourquoi vous demandez cela ici. Si vous avez une question sur la programmation, vous devriez la poser dans un article séparé. S’il vous plaît, n’essayez pas de l’ajouter à celui de quelqu’un d’autre. Cette réponse a été traduite par machine de l’anglais pour votre commodité.
0
😹Don’t title your question on how clear and well written the question is, lol. That being said it does look pretty clear this time, but with virtually no C++ knowledge I’m not sure what to tell you.
0
I’m not sure why you’re trying to force one programming language into another’s working mechanic. What are you actually trying to do in the program? It’s like you want to learn to fly whilst following automobile traffic laws.
0
And you cant cast in Python if im not mistaken
0
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦 python does allow casting for basic data type like below:
b = 1.3
print(int(b)) prints 1 and casting happens. Right? Or this is also an object creation only?
0
Tu parle français?
0
Wilbur Jaywright. Yes
0
Look, i dont know what casting is cuz i learned python in Ukrainian, not English.