0

So I was trying to do a bit of programming problems on LeetCode and I saw a method of class declaration that I'm not so familiar with. This was how it was:

class Solution:
    def romanToInt(self, s: str) -> int:

And what I'm used to is something more like:

class Solution:
    def romanToInt(self, s):

Is there a difference between the two?

SidKay
  • 3
  • 2
  • 1
    https://stackoverflow.com/questions/14379753/what-does-mean-in-python-function-definitions – omercotkd Mar 25 '22 at 13:29
  • Does this answer your question? [What does -> mean in Python function definitions?](https://stackoverflow.com/questions/14379753/what-does-mean-in-python-function-definitions) – EJZ Mar 27 '22 at 20:31

1 Answers1

3

It is a type annotation that has no runtime significance (in the absence of other libraries like Pydantic), but allows for some static type checking.

In this case, it simply means that the type of s is a string, and that the method returns an int

Ben
  • 4,980
  • 3
  • 43
  • 84