+ 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?

11th Oct 2019, 6:34 AM
our dream
our dream - avatar
4 odpowiedzi
+ 2
whitespace is also a character
11th Oct 2019, 6:35 AM
null
null - avatar
+ 2
Hi. White space gets counted too. That should be 15th if I counted correctly. Cheers. C
11th Oct 2019, 6:36 AM
ChrA
ChrA - avatar
+ 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
11th Oct 2019, 9:39 AM
Lothar
Lothar - avatar
+ 1
Wow, okay. Thanks
11th Oct 2019, 6:36 AM
our dream
our dream - avatar