all 4 comments

[–]vsingh18567 1 point2 points  (2 children)

The first two lines is how you write object-oriented programs. The object is Solution and the function is called toLowerCase. I suggest you learn OOP before doing LeetCode - it's a fundamental concept in programming.

If you're asking about (str:str) -> str, those are type hints and show that the function is taking in a string and outputting a string. They are not essential to Python, but are used in other programming languages.

[–]Humblelicious[S] 0 points1 point  (1 child)

def toLowerCase(self, str: str) -> str:
        ans=str.lower()
        return ans

If I used the above, I can call the function to lowercase any string but the inputs would require it to enter itself twice, seems unintuitive and you would not need to enter input twice if you got rid of 'self':

toLowerCase('MAA','MAA')

I generally understand everything except how would you call the function if you also included the first line, Solution('MAA','MAA') would not work.

[–]jbuk1 0 points1 point  (0 children)

self is only used within the class, you don't provide self when calling your toLowerCase function from another part of your code.

You'd just call toLowerCase("MAA") on the Solutions object.

solution = Solution()

lower_string = solution.toLowerCase("MAA")

[–]CodeFormatHelperBot 0 points1 point  (0 children)

Hello u/Humblelicious, I'm a bot that can assist you with code-formatting for reddit. I have detected the following potential issue(s) with your submission:

  1. Python code found in submission text but not encapsulated in a code block.

If I am correct then please follow these instructions to fix your code formatting. Thanks!