0
  class pair:
    def __init__(self):
        self.min = 0
        self.max = 0
 
def getMinMax(arr: list, n: int) -> pair:
    minmax = pair()

how does this arr: list and n : int are working ?
and - > pair , is working and how does class object is form by this way ??

Ryan Haining
  • 35,360
  • 15
  • 114
  • 174
  • 1
    Those are type hints: https://docs.python.org/3/library/typing.html – UnholySheep May 06 '21 at 20:54
  • [What does -> mean in Python function definitions?](https://stackoverflow.com/q/14379753/3890632) and [Use of colon in variable declarations](https://stackoverflow.com/q/51639332/3890632) – khelwood May 06 '21 at 20:59

2 Answers2

1

Those are type signatures. And you can read all about them in PEP 484. They don't do much of anything on their own, but they're extremely useful with a tool like mypy.

def getMinMax(arr: list, n: int) -> pair:
    minmax = pair()

This declares that getMinMax takes two arguments: arr and n. The type of arr is list and the type of n is int. The function will return a value of type pair. Again, none of this affects Python proper (although you can access the type signatures in Python using reflection, they have no bearing on the runtime by default), but you can use it to run compile-time verification on your code.

If you found this code in the wild and just want to interact with it, you can safely ignore the type annotations. But I strongly recommend you read PEP 484 (it's actually quite digestible, and I recommend reading it in full). It's got a ton of useful stuff, and it's very helpful.

Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116
0

That's all just a type hinting. Interpretator does not check type of parameters, it's like hint for developers and IDE. arr: list mean that parameter arr must be a list and n must be int. -> show what type must be in returned value. You must add return minmax at the end of function for following type hinting.

Maksym Sivash
  • 63
  • 1
  • 6