Why can we not lower(var)


Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output

Why can we put the variable in the method here:
print len(test)

But not to get rid of capitalization:

The following does not work, but why?
t = “Test”
print lower(t)

EDIT: Fixed Variable


To call an object (such as a function) you first have to get a reference to that object (which you do by typing a name referring to it, like len). A whole lot of stuff is already defined when you start python, and more so if you import other modules.
But if you try to use a name that isn’t defined… Well, you’ll be told that’s not possible.

As for why len exists at module level and why lower is a string attribute, that’s because lower is string behaviour while len operates on anything that defines a length

t = "Test"
print lower(test)

should be

t = "Test"
print t.lower()

the test variable doesnt exist


My apoligies. I mean
print lower(t)

In terminal I get:
NameError: name ‘lower’ is not defined


the syntax of the lower method on python is:




so you would want to try:

print t.lower()


To be a bit picky, it’s not syntax. They’re both valid syntax, but one of them hasn’t been defined

It’s like saying:

print a + b

Without first defining a/b


I understand that, I was just trying to understand the thinking behind this. I am new to Python so the () throws me off a bit.


str.lower() is a string method while len() is a function like print()


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