Game Designer Game Designer - 3 months ago 14
Python Question

Checking whitespace in a string (python)

Why do I always get

YES!!!
? I need to return
NO!!!
if the string contain a whitespace (newline, tap, space)

user = "B B"

if user.isspace():
print("NO!!!")
else:
print("YES!!!")

Answer
def tt(w): 
    if ' ' in w: 
       print 'space' 
    else: 
       print 'no space' 

>>   tt('b ')
>> space
>>  tt('b b')
>> space
>>  tt('bb')
>> no space

I am in train, sorry for not explaining.. cannot type much..

Comments