Changes between Version 135 and Version 136 of ControlSystems/SoftwareTeam/IntroToPython


Ignore:
Timestamp:
Sep 5, 2017, 12:02:48 AM (8 years ago)
Author:
cdelgigante
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ControlSystems/SoftwareTeam/IntroToPython

    v135 v136  
    8282Three things to note about this program:
    8383
    84  1. The double equals in `location=='HERE'` on the first line.   It is called an ''expression''.   In this case it is an equals expression (other kinds of comparisons in python are listed here) .  It returns ''True'' when the condition evaluates to ''True'', otherwise its ''False''.   Note on that line the word 'HERE' is in quotes.  That's to indicate its a string (a text value) not some variable (which doesn't exist).  If you used `=` instead of `==` it wouldn't work as you expected because it would be a variable assignment.   If a If-Then-Else statement ever behaves in an unexpected way, check for this problem first, its a really common mistake.
     84 1. The double equals in `location=='HERE'` on the first line.   It is called an ''boolean expression''.   In this case, it tests equality (some kinds of boolean expressions in Python are listed [[https://www.pythonlearn.com/html-008/cfbook004.html|here]]) .  Boolean expressions return ''True'' when the condition evaluates to ''True'', otherwise they return ''False''.   Note on that line the word 'HERE' is in quotes.  That's to indicate its a string (a text value) not some variable (which doesn't exist).  If you used `=` instead of `==` it wouldn't work as you expected because it would be a variable assignment.   If a If-Then-Else statement ever behaves in an unexpected way, check for this problem first, its a really common mistake.
    8585 1. Spacing and indents are important in Python.  the line "We're here..." and the line below it are indented to indicate they are part of a statement ''block'' that runs when the condition evaluates to `True`.   The second block on the else is run when the condition to `False`, and only contains one line.   If you want to do stuff outside of the IF-THEN, don't indent it like the first and last print statements.
    8686 1. You'll see that a few of the print statements end with a `\n`.  This is called a ''escape sequence'', and its shorthand for a newline.  When the computer sees it in a print statement, it will add an extra line to the output. [[Here|https://www.quackit.com/python/reference/python_3_escape_sequences.cfm]] are some other escape sequences you can use.