How to cast in python : 2 | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 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
11 Respostas
+ 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