Changes between Version 23 and Version 24 of ControlSystems/SoftwareTeam/IntroToPython
- Timestamp:
- Sep 4, 2017, 5:27:40 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ControlSystems/SoftwareTeam/IntroToPython
v23 v24 79 79 Three things to note about this program: 80 80 81 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 statement ever behaves in an unexpected way, check for this problem first, its a common error.81 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. 82 82 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. 83 83 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. See here for other escape sequences you can add.