How do you cast an instance to a derived class?

前端 未结 5 1900

I am trying to use a little inheritance in a Python program I am working on. I have a base class, User, which implements all of the functionality of a user. I am adding the co

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-13 23:43

    Python is a dynamically-typed language, so the concept of "casting" doesn't exist. If the object is already an UnapprovedUser, then you can already call all methods that exist in that class, without having to cast.

提交回复
热议问题