Python Forum
I couldn't understand the output of the below code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I couldn't understand the output of the below code
#1
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..?
Reply
#2
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem in output of a snippet code akbarza 2 350 Feb-28-2024, 07:15 PM
Last Post: deanhystad
  Unable to understand the meaning of the line of code. jahuja73 0 299 Jan-23-2024, 05:09 AM
Last Post: jahuja73
  I cannot able to see output of this code ted 1 749 Feb-22-2023, 09:43 PM
Last Post: deanhystad
  Couldn't install a go-game called dlgo Nomamesse 14 3,073 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  why I dont get any output from this code William369 2 1,116 Jun-23-2022, 09:18 PM
Last Post: William369
  How can I organize my code according to output that I want ilknurg 1 1,158 Mar-11-2022, 09:24 AM
Last Post: perfringo
  Unable to understand how given code takes a fixed input value, without inputting. jahuja73 4 2,670 Jan-28-2021, 05:22 PM
Last Post: snippsat
  Don't understand example code from a textbook lil_fentanyl 1 1,824 Jan-25-2021, 07:02 PM
Last Post: nilamo
  Why this code not getting desired output ? MDRI 2 2,514 Sep-18-2020, 02:11 AM
Last Post: MDRI
  Unable to understand a statement in an existing code ateestructural 1 2,214 Aug-01-2020, 09:38 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020