I did not understand why do we put full-stop before lower() ?? we did not put full-stop before len() ??
len is always available whereas
str.lower is a member of the
str class, and is therefore only accessible through that class or through one of its instances (a string)
. operator is used to access members of values.
Here's a list of those always-available functions, you'll recognize some of them but not many. Mostly I just want to expose you to the documentation. (Google will get you to the right place if you need to look something up)
print(len) # Tells you it's a function print(lower) # NameError - no such name defined print(str.lower) # Tells you this is a method print(str.len) # AttributeError - `str` doesn't have a member named `len` print('HELLO'.lower()) # accesses the `lower` member and calls it print('HELLO'.len()) # Error, again, no such attribute of string print(len('HELLO')) # calls `len` with 'HELLO' as argument, prints 5
Lemme Slide into those Community Forums...