Python 用更长的方式解释程序
有人能解释一下吗?我真的不明白那部分代码,它是如何工作的。有人能把它写出来吗 如果thing=“x” 如果事物=Python 用更长的方式解释程序,python,Python,有人能解释一下吗?我真的不明白那部分代码,它是如何工作的。有人能把它写出来吗 如果thing=“x” 如果事物= thing = "x" if thing.lower() == "o" else "o" 相当于 if thing.lower() == "o": thing = "x" else: thing = "o" 相当于 if thing.lower() == "o": thing = "x" else: thing = "o" thing被赋值“x”
thing = "x" if thing.lower() == "o" else "o"
相当于
if thing.lower() == "o":
thing = "x"
else:
thing = "o"
相当于
if thing.lower() == "o":
thing = "x"
else:
thing = "o"
thing
被赋值“x”
如果thing.lower()
是“o”
(即,行的该段计算结果为True
),否则它被赋值“o”
如果thing.lower()
是“x”
如果thing.lower()
是“o”
(即,该行段的计算结果为True
),否则它被指定为“o”
。