Chapter 1 code segment Flashcards
Snippet
A small region of re-usable source code, machine code, or text
Terminal
Text-based interface to the computer
Type ipython on terminal and press Enter to enter interactive mode
Get:
Python 3.7.0 | packaged by condo-forge | (default, Jan 20 2019, 17:24:52)
Type ‘copyright’, ‘credits’ or ‘license’ for more information
IPython 6.5.0 — An enchanced Interactive Python. Type ‘?’ For help.
In [1]
Here [1] is prompt, indicating that IPython is waiting for your input. Can type math equation if you want to
Integers
Whole numbers
Floating-point numbers
Whole n umbers with decimal points
To exit interactive mode
<Ctrl> + d (or <control> + d)
This displays the prompt “Do you really want to exit ([y]/n)?” The square brackets around y indicate that it’s the default response-pressing Enter submits the default espouse and exits
</control></Ctrl>
To exit interactive mode on Linux or macOS type what?
Type <Ctrl>+d(or<control>+d) twice</control></Ctrl>
In IPython interactive mode, you’ll need small bits of Python code called ______ and immediately see their results
Snippets
In IPython ________ mode, you’ll execute Python code loaded from a file that has the .py extension (short for Python)
Script
Evaluate the expression 5 * (3 + 4) both with and without the parenthesis. Do you get the same result? Why or why not?
You get different results because snippet [1] first calculates 3 + 4, which is 7, then multiplies that by 5. Snippet [2] first multiplies 5 * 3, which is 15, then adds that 4
What does it mean if a file name ends in .py?
The .py extension indicates that the file contains Python source code.
Variables
Stored values for later use in your code. Ex:
In [1]: x = 7
These are known as statements, it is a specified task to perform. The entire statement is an assignment statement.
Assignment symbol
In the variables example, this is (=)
Addition operator
+
Binary operator
Has two operands such as x + y