Using lower()


#1



https://www.codecademy.com/courses/python-beginner-sRXwR/1/2?curriculum_id=4f89dab3d788890003000096


According to me, the code should work when a string is declared by parrot="HELLO"
print lower(parrot)

I think it should output the string in lower case. But it works when syntax is: parrot.lower()

parrot="HELLO"
parrot.lower()


#2

Hi there, the reason why lower works like this is because the .lower() function will only work with a string. This is called "dot notation", any function that is called in this way will only work using a string:

x = "parrot"
print x.lower()
print x.upper()
------------------
parrot
PARROT

The other functions in this section, len() and str(), can be used on other data types, such as integers. Hope this helps you :slight_smile:


#3

Misleading. All classes have methods, not just strings. Dot notation is used to call a class method on an instance of that class. The instance then becomes the execution context for the method.

string.lower()
  |        \
context   method

https://docs.python.org/2/library/string.html

https://docs.python.org/2/library/stdtypes.html


#4

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