+ 1
Function
Hi, I have a question about len function. Phrase = "Giraffe Academy" Print(len(phrase)) It prints 15 and actually its 14 letters there Why please?
4 odpowiedzi
+ 2
whitespace is also a character
+ 2
Hi.
White space gets counted too. That should be 15th if I counted correctly.
Cheers. C
+ 2
If there is a need to count characters without spaces you can try this:
phrase = "Giraffe Academy"
print(len(phrase)) # count with space
print(len([i for i in phrase if not i.isspace()])) # count without space
+ 1
Wow, okay. Thanks