Python - Doubt related to structure, I believe

Asked

Viewed 34 times

0

Can someone explain to me what it is and in what situation applies the way to create methods below:

 def show_preprar_dados(self) -> object:
        pass

I don’t know what it means and what it’s for when the arrow appears next to the function name.

I don’t know if I’ve opened the question properly to this subject, so help me.

Grateful for the understanding.

  • Do you know how typing works in other languages? Have you ever declared an object variable in another language?

  • Typing that I know, even because I’m new, is when you declare a variable of type (string, Boolean, Integer...) now I don’t remember ever having declared variable of type object. Can you help me understand how this works and when I can apply it, and its benefits? Grateful.

  • Boolean, integer, char, string, and float types are practically basic typages in programming languages. The object type is present in object-oriented languages such as Java, Python, C++ (not the common C), PHP, among others. Object type variables are how you insert an entire object into a variable.

  • Imagine that you created the Animal object (which possesses the animal class), and in it possesses the method called bark(). Let’s assume in any language. I declare the anim variable of the object type. That is: Animal anim; And from there I can exercise the anim.latir method.().

  • Only an example for you not to get confused. But for this you can find more answers in the documentations of the programming languages. Which in your case is python. Go looking and trying to figure out how to call an object and put in a variable.

  • So, the Animal object you say would be a file called "Animal.py" in my Python case, and inside I would have the class "animal" with a bark() method.? To declare the variable of the obejto type, you would do so: anim = Animal() With this calling it in import. Or did I get it wrong? Because if so, I already do it that way. Just don’t understand why I declare a method like this: def metodo_animal(self): -> Animal()

  • In this method of your question, he obligatorily transforms this method of yours into an object. (Objects not necessarily need to be classes). And this way ->Animal() will not work. and yes def metodo_latir(self) -> Object:

  • I think I confused you using classes as an example. I don’t know how you’re learning about object orientation. But on your question, you are transforming your method being it necessarily an object, pose to be float, int, double, but it is Object.

  • Okay, I think I get it. But what would be the practical application of this? What differs from me importing a class and declaring a method that way?

  • Analyse this question: https://answall.com/questions/344486/por-que-orientates%C3%A7%C3%a3o-objects-n%C3%a3o-serve-for-the-majority-of-cen%C3%a1rios

  • 1

    I hope I’ve helped

Show 6 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.