quizzn
Discover Groups Sign up Log in
Home › Technology › Python tricks

Inline if statement:
if x:
y=100
else:
y=20

  • if x: y=100 else y=20

  • x=20 if x else 100

  • Correct answer

    y=100 if x else 20

This question is one of 8 in Python tricks. Test yourself on all of them.

Practice quiz Flashcards

Log in to add an explanation.

Report a problem

Advertisement

More from Python tricks

  • >>> x = 60 >>> 1 < x < 100
  • >>> x = 4 >>> 9 < x < 20
  • >>> x = 5 >>> x < 10 < x*10 < 100
  • >>> x = 10 >>> 10 == x > 7
  • >>> d = {'four': {'six': 6, 'five': 5}, 'three': [3, 33, 333], 'two': 2, 'one': 1} Print…
  • Replace RED space
  • One-line class declaration: >>> class MyClass(object): >>> spam = "I am spam"
All 8 questions →

Advertisement

© 2026 Quadrupley Inc. About Blog Feedback Privacy Terms