sweigart chapter 1 Flashcards
interactive shell/Read-Evaluate-Print Loop (REPL)
lets you run (or execute) Python instructions one at a time and instantly shows you the results.
expressions
consist of values (eg. 2) and operators (eg. +) and can always evaluate (reduce) down to a single value. a single value is also considered an expression but it evaluates only to itself. you can use expressions anywhere in Python code where you could also use a value.
precedence
the order of operations. python math operators are similar to mathematics. parentheses can be used.
data type
a category for values, where every value belongs to one data type.
strings
text values surrounded by single quote (‘) characters, also known as strs.
integer
eg. 1
floating-point number (floats)
incorporates a decimal point, eg. 1.0
empty/blank structure
a string with no characters in it (“).
string concatenation operator
when + is used on 2 string values it joins the strings.
string replication operator
when * is used on one string value and one integer value. it evaluates the expression down to a single string value that repeats the original string a number of times equal to the integer value.
variable
a box in the computer’s memory where you can store a single value. if you want to use the result of an evaluated expression later in your program.
assignment statement
used to store values in variables. it consists of a variable name, an equal sign (assignment operator), and the value to be stored.
initialised
when the variable is created the first time a value is stored in it. after that, you can use it in expressions with other variables and values.
overwriting a variable
when a variable is assigned a new value and the old value is forgotten.
camelcase
using capitalised letter for every new word instead of underscores. eg. current_balance becomes currentBalance.
file editor
used to write entire programs. in the file editor, instructions will not be run when you press enter. instead, you can save a file with many instructions and then run the program. it also does not have the»_space;> prompt. you can start the program in the file editor so that it will start running in the interactive shell.
terminates
when there are no more lines of code to execute, the Python program stops running.
commenting out
every line following a hash mark (#) is called a comment and will be ignored by Python. it can be used as a note to yourself or to temporarily remove a line of code while testing a program.
print() function
indicates that Python has to print out the text in a string.
calling
executing a line with a function
passed
when a line is executed and a function is called, the string value is passed to the function.
argument
a value that is passed to a function call.
len() function
evaluates to the integer value of the number of characters in a string value.
input() function
waits for the user to send some text. this function evaluates to a string equal to the user’s text.
int() function
can be helpful if you have a number as a string value that you want to use in mathematics. floating-point numbers will always be evaluated downwards.