.len() vs *len()


#1



I am not stuck with this lesson, I managed to figure it out with some research, but what I could not find was what the difference between .len() and *len() is.

When len was introduced it only talked about .len(). the code below is the code that worked and I am just curious as to the significance/reason behind the *len() as the .len() does not work.


text = text.replace(word, '*'*len(word))


#2

Hi @jacobhilt

The *len() function doesn't exist in python. Here

If you gave a space between * and len, you can see that it works the same:

text = text.replace(word, '*' * len(word))

The asterix(*) is used in multiplication in this case. It multiplies the string '*' with the length of the variable word. Let's say the length of word was equal to 5. 5 times '*' is equal to *****.

Hope this helped! :wink:


#3

Wow, that makes so much more sense. I got myself so confused looking at it and never even noticed that. Looks like it may be time to take a break for the night :wink:

Thanks!


#4

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