Why do string commands such as upper() have "()"?


#1

Why do commands like upper() have parenthesise "()" since they work with dot notation so for lets say

example = "string"

to print it in upper case you would type

print example.upper()

and NOT

print upper(example)

So why does upper() have "()"? and if you can use that "feature" of the command then what sort of arguments can you put in those parenthesise ?


#2

I don't Know , think if we create a variable with name example.upper (in your case that will return EXAMPLE )


#3

I've been digging around to try to find an answer to this as well but all I've found is more examples. My best guess is commands like len() are analysis functions whereas upper() and lower() are transforms, i.e. the former gives you data on the string and the latter alters it. As for why you have the (), I think that might just be the standard formatting for string commands. In a sense, it's just as out of place that you don't write len() as Example.len(). I'd love to be corrected however.