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?

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.