[英]If, elif, and else conditions are not working correctly in my code
def greeting(string):
greet=["Good Morning"+' '+string]
return(greet)
print("Enter your name")
name=input()
if(name is "Saptarshi"):
greet=greeting(name)
print(greet)
elif(name is "Gurpreet"):
greet=greeting(name)
print(greet)
else:
print("No greeting for you!")
Use ==
instead of is.使用
==
而不是 is。
Python is
operator compares two variables and returns True
if they reference the same object. Python
is
运算符比较两个变量,如果它们引用同一个对象,则返回True
。 If the two variables reference different objects, the is
operator returns False.如果两个变量引用不同的对象,则
is
运算符返回 False。
a = 100
b = a
result = a is b # True
d = 10
e = 10
result = d is e # False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.