• Profile
  • Resume
  • Portfolio
  • Blog
Avatar

Nelson Silva

A human. Being. Coffee lover.

Blog

I Write My Thoughts Here

if, elif and else in Python

September 24, 2021 Python

In this post, you will learn how to work with decisions (if, elif and else) so that you can use that same knowledge and thus evolve.

'''
  (if) condition is true:
    the code inside the if is executed
  (elif) condition is true (elif only occurs when the if condition is false):
    the code inside the elif is executed
  (else) without condition (only occurs when the if/elif conditions are false):
    the code inside the else is executed
'''

x = 30

if x == 10:
   print('The value of x is equal to 10.')
elif x == 20:
   print('The value of x is equal to 20.')
else:
   print('The value of x is different from 10 and 20.')

# The value of x is different from 10 and 20.

Don’t forget to watch the video and you can always read this post in Portuguese.

Happy coding!

Previous Next

Categories

  • Announcements
  • Python
  • C#
  • Java
  • Go

Latest Posts

  • for Loop in Go
    May 5, 2022
  • Switch in Go
    May 4, 2022
  • Comparison Operators in Go
    May 3, 2022
+351913416022
contact@nelsonsilvadev.com
Porto, Portugal
Nelson Silva © 2022 All Rights Reserved