+ 1

Python considers blank or white spaces as a charector or not?

Or that question its answer was wrong? str = "hello friends" print (str[0]+str[8]) # hi //counted the space also.

10th Jun 2020, 2:14 PM
Azad m. A.
Azad m. A. - avatar
5 odpowiedzi
+ 8
you can use the string method isspace() to check if a a tring is completely built of spaces or if a single character is a space. Whitespaces recognized by the function are: space, tab, newline, carriage return, vertical tab, form feed But there are some more whitespaces in unicode like nonbreaking space and so on. Normally these are not used in coding environments, but by doing copy & paste from the web or from a text processing app you can get these characters in your code.
10th Jun 2020, 3:29 PM
Lothar
Lothar - avatar
+ 6
Az.A. it fails on isalpha() Could u mean this?
10th Jun 2020, 2:55 PM
Oma Falk
Oma Falk - avatar
+ 5
Yes it does. hellofriends and hello friends are different.
10th Jun 2020, 2:22 PM
Oma Falk
Oma Falk - avatar
+ 1
Oma, I can remember that some where else did not count it as char..you alright as in string the case is different.. Do you know where else it is not counted?
10th Jun 2020, 2:24 PM
Azad m. A.
Azad m. A. - avatar