Python: if Statements and Comparison Operators

  1. Introduction to Python
  2. Python: Choosing a Text Editor or IDE
  3. Python: Hello World
  4. Python: Variables, Strings and Numbers
  5. Python: Variable Naming
  6. Python: Math, Familiar
  7. Python: Math, Less Familiar
  8. Python: Mathematical Order of Operations
  9. Python: Introducing PEP 8
  10. Python: Text Concatenation
  11. Python: if Statements and Comparison Operators
  12. Python: else and elif statements
  13. Python: Testing Multiple Conditions
  14. Python: Testing Sets of Conditions
  15. Python: Nested if Statements
  16. Python: Lists
  17. Python: Adding To and Changing Lists
  18. Python: Lists: Take a Slice, Delete Elements, Popping Elements
  19. Python: Tuples
  20. Python: for Loops
  21. Python: Nested for Loops
  22. Python: Capturing and Formatting User Input
  23. Python: Dictionaries
  24. Python: Functions
  25. Python: While Loops
  26. Python: Data Files
  27. Python: Using Pexpect
  28. Python : Using Pexpect : ftpTestOffload.sh
  29. Python : Using Pexpect: ftpTest.py
  30. Python: DCL Conversion to Python

Go to Chapter 9 in A Smarter Way.

An if statement in Python requires some careful punctuation and indentation:

    if this_cat == my_cat:
        # This cat is mine.
        print("%s is my cat!" % cat.title())

Note the comparison operator, ==, as opposed to the assignment operator, =.

Exercises

See http://www.asmarterwaytolearn.com/python/9.html

Go to Chapter 10 in A Smarter Way.

Note the list of operators available to you:

== # is equal
!= # not equal
> # greater than
< # less than
>= # greater or equal
<= # less or equal

Exercises

See http://www.asmarterwaytolearn.com/python/10.html

See http://introtopython.org/if_statements.html

  1. Return to examples.py.
  2. Do a test on the author’s name. If the name variable holds the proper name, print “Authorized Edition”.
  3. If the name variable doesn’t hold the proper name, print “No an Authorized Edition!”