Lower() command


#1

why doesn’t print lower(“Norwegian Blue”) work but len(“Norwegian Blue”) works ?

Strings and Console Output


#2

If I define the variable a I can use it, for example, I can print it
If I leave the variable b undefined, I can’t use b

lower isn’t defined, so you can’t use it

strings have a method named lower though, perhaps that’s what you’re looking for.

Note that lower isn’t a command. It’s a name. In this case, it doesn’t refer to anything. len is also a name. len refers to a function, so you can use len to reference that function, and call it.


#3

Yes, I am referring to method lower() . Why is the syntax different for lower() and len() ?


#4

They’re defined in different places. So you type out the place, followed by the call operator ()
I wouldn’t say the syntax is different. They’re both callable objects, you treat them more or less the same way.

While this isn’t how you should be using lower, it demonstrates that the syntax is the same:

a = str.lower
b = len

print a('HI')  # hi
print b('HI')  # 2

It’s not the syntax that changes, it’s the operations required to obtain them. As said, they’re defined in different places.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.