Python Forum

Full Version: I couldn't understand the output of the below code
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
user = 'Admin'
logedin = 'False'

if logedin:
    print('welcome')
else:
    print('pl login')
the output is welcome

I defined logedin as a string how if condition verify the variable and given the output..?
I think it takes boolean value, thus when it checked on logedin it had some value and it turned to true block.
if empty string it would be on else block.

either you may use logedin type as boolean or if condition with match string.

user = 'Admin'
logedin = False
logedin_test= 'False'
logedin_test1= ''
logedin_test2= ' '

print(bool(logedin))
print(bool(logedin_test))
print(bool(logedin_test1))
print(bool(logedin_test2))


if logedin:
	print('welcome',bool(logedin))
else:
	print('pl login',bool(logedin))
best Regards,
Sandeep

GANGA SANDEEP KUMAR