+ 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

17th May 2024, 5:24 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
12 Answers
+ 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
17th May 2024, 5:54 PM
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦 - avatar
+ 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
24th May 2024, 1:17 AM
Vitaly Sokol
Vitaly Sokol - avatar
+ 1
Modified title.
17th May 2024, 5:28 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 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.?
18th May 2024, 9:05 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 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é.
19th May 2024, 4:15 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
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.
17th May 2024, 5:27 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
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.
17th May 2024, 5:35 PM
Wilbur Jaywright
Wilbur Jaywright - avatar
0
And you cant cast in Python if im not mistaken
18th May 2024, 7:58 AM
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦 - avatar
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?
18th May 2024, 9:07 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
0
Tu parle français?
19th May 2024, 11:44 AM
Benoît Tagbino
0
Wilbur Jaywright. Yes
8th Jun 2024, 8:54 AM
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦 - avatar
0
Look, i dont know what casting is cuz i learned python in Ukrainian, not English.
23rd Jul 2024, 5:43 AM
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦
🇺🇦🇺🇦🇺🇦Coding Nerd🇺🇦🇺🇦🇺🇦 - avatar