Python三元运算符Can';t分配
这条蟒蛇有什么毛病?每次我尝试执行时,它都会说不能赋值给条件表达式 您不需要第二条Python三元运算符Can';t分配,python,python-3.x,Python,Python 3.x,这条蟒蛇有什么毛病?每次我尝试执行时,它都会说不能赋值给条件表达式 您不需要第二条消息=:message=“Allowed”如果年龄>=18岁,否则“notallowed”将起作用 基本上,Python三元运算符的工作原理如下: [result]=[thing if true]if[condition]else[thing if false] 所需的只是一个条件和两个单独的选项:您不需要两次分配message变量。您的意思是message=“Allowed”if age>=18,否则“not A
消息=
:message=“Allowed”如果年龄>=18岁,否则“notallowed”将起作用
基本上,Python三元运算符的工作原理如下:
[result]=[thing if true]if[condition]else[thing if false]
所需的只是一个条件和两个单独的选项:您不需要两次分配message
变量。您的意思是message=“Allowed”if age>=18,否则“not Allowed”
。您应该搜索错误消息。
age = 22
message = "Allowed" if age >= 18 else message = " not allowed"
print (message)