1

I have read examples of python shorthand-if in the stackoverflow but still can not figure out how to solve my own simple problem. I want to print("this is a prime number") else print(this is not a prime number) based on the [boolean] return value of the following function:

is_prime(2) 

How should I write a short hand method for?

1 Answer 1

4

Do you mean conditional expression?

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'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.