What's the logical value of "string" in python?

Posted by Kamran on Stack Overflow See other posts from Stack Overflow or by Kamran
Published on 2010-12-25T21:45:51Z Indexed on 2010/12/25 21:53 UTC
Read the original article Hit count: 247

Filed under:

I erroneously wrote this code in python:

name = input("what is your name?")
if name == "Kamran" or "Samaneh":
    print("That is a nice name")
else:
    print("You have a boring name ;)")

It always prints out "That is a nice name" even when the input is neither "Kamran" nor "Samaneh".

Am I correct in saying that it considers "Samaneh" as a true? why?

By the way, I already noticed my mistake. The correct form is:

if name == "Kamran" or name == "Samaneh":

© Stack Overflow or respective owner

Related posts about python