Why len() and lower() are used differently?


#1

len(string)

string.lower()

why we have to use the methods differently?

are they something different syntax??



Replace this line with your code.


#2

len() is a function where as .lower() is a method of string class

function and classes will be covered in this course, we can talk about this in more detail once you learned about function and classes

going in-depth about this now might be a bit confusing


#3

len is a function, lower is a string method.

len may be applied across multiple classes, whereas lower is confined to the str class. The object must be a string to call this method.

We can query the length of strings, lists, and tuples, and possibly even sets and dictionaries, though I am not sure without testing. Iterable objects all have a length attribute.

>>> len({1,2,3,4,5,6})                            # a set
6
>>> len({'1':1,'2':2,'3':3,'4':4,'5':5,'6':6})    # a dict
6
>>>

#4

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