我已经在stackoverflow中阅读了python速记的例子,但仍然无法弄清楚如何解决我自己的简单问题。我想根据以下函数的 [布尔] 返回值print("this is a prime number")
else print(this is not a prime number)
:
is_prime(2)
我应该如何编写速记方法?
你是说条件表达式吗?
print("this is a prime number" if is_prime(2) else "this is not a prime number")
print('this {} a prime number'.format('is' if is_prime(2) else 'is not'))