3.2 Terms
logical operators
&& [and] || [or] ! [not] A representation of a logical statement that is used to examine the relationship between two values and determine whether the statement is true or false (Boolean conditionals).
list object
A collection of data values that do not have to be the same type. Each item in a list is called an element.
Why would you use different variable letters?
Use different variable letters, comment out loops as you get the desired output, or use separate python files.
Nesting
Using a function as an argument within another function.
self.first.name
part of the code that retries specific info about the class
pop with a position
removes and returns the item at position
pop
removes and returns the last item
remove
removes the first occurrence of item
count
returns the number of occurrences of item
what is printed by the following statements alist = [4, 2, 8, 6, 5] alist = alist.pop(0) print(alist)
4
For loops
A control flow statement that allows a set of instructions to be executed repeatedly. A for loop is usually used when the number of iterations is predefined "execute this loop so many times". Otherwise, a programmer might use a while loop, which would execute the loop repeatedly as long as a certain condition is met.
While loops
A control flow statement that is a repeating if statement. The while loop will continue to execute indefinitely long as the condition being evaluated is true.
What does a function definition header begin with?
A function definition header begins with the keyword "def" and is followed by an identifier for that function
Range function
A function that identifies a number to start at, a number to stop at, and how much to change by each time the program executes the loop. The function will loop as many times as necessary until it gets to the end value.
Method
A function that is a member of a class
Concatenate
A joining together of separate items —without changing them—into one place. For example, the concatenation of two strings such as "Hello" and "world!" would return "Hello world!".
Post
A list that contains a class of objects, such as in social media posts
modulo
A mathematical operator that performs division, but returns the remainder.
Boolean Expression
A processing decision branch using comparison operators (= ≠ > <) that is defined to return a Boolean value ("True" or "False"). By using Boolean expression to ask questions, the program can determine what to do next.
Skeleton Code
A program that has many missing pieces to be filled in. Often skeleton code contains comments to inform the programmer what kind of code needs to go where, so others can take the tracer round of the program and modify it for their own needs.
conditional statement
A programming statement that evaluates a true/false Boolean expression to determine the next steps in a program. Conditional statements are often written as 'if-then' or 'if-then-else' statement
chained conditional statement
A series of conditionals that a computer moves through until it finds the one that is true.
element
A single entry of a list. An element can be different data types, such as integer, float, string or Boolean.
index
A specific location by order for an individual element in a list. The position of an item in a list is often called an index.
Algorithm
A step-by-step procedure for solving a problem, especially by a computer.
object-oriented programming
A style of programming language that focuses on creating reusable patterns of code, in contrast to procedural programming, which focuses on explicit, sequenced instructions.
Abstraction
A technique or process that manages complexity in a program or computer system. Abstraction "hides" details or removes duplication, allowing the programmer to focus on high-level considerations and functions rather than the rules of a programming language.
class
An abstraction defining a type of object, with methods (instructions that can be executed) and attributes (variables to store data).
When do you use "\"?
At the end of a line while typing a string, type \ then press Enter to continue a long string on the next line in Python but still have the entire string output print on the same line to a user.
What does "\n" do?
Creates a new line in a print string outline
What does "\t" do?
Creates a tab in a print string output
Why don't you call functions from within their definitions?
Do not call functions from within their definition; you will produce unexpected results.
How would you make a function that belongs to a class accessible?
If the function belongs to a class and you would like it to be accessible as a method (from outside of the class to get information contained in specific instances of that class), the first argument in the function definition should usually be "self", as it is in this function.
Boolean Value
One of two values, such as "True" or "False", that allows a computer to know what step in the conditional statement process to execute next. (Remember, to note the capitalization. In Python, Boolean values must start with a capital letter, or the program will not recognize them as keywords.)
bash
The Bourne again shell (Bash) is a common application to offer a shell command line; other common shell applications are the C shell, the Bourne shell, and the Kern shell.
Cloud collaboration
The ability to view, edit, and share documents online.
What should you do if an Error Alert appears?
The files depend on each other, so changing the name of a file means you need to update the first few lines of the other files you are working with that access that file. Read the errors. They will tell you which file and what line to look at. Start with the first error, as later errors might adjust after you fix the first one in the program. Capitalization matters! Double-check that you are using consistent capitalization throughout all files with the same words. If you get outputs that include <bound method ...>, check whether you included the parentheses when you called a method. Debugging tip: You may see an output that you were not expecting, because it is coming from a different file, through the file you are running. Be sure to look at the output of both skeleton files when debugging
Iteration
The process of repeatedly running a set of computer instructions until some condition is satisfied.
What should you do when you copy and paste code?
When you copy and paste code as a guide, you may need to revise parts of what you pasted so the program addresses the part of the program you copied it into, instead of doing the part you copied it from multiple times.
What can you use the tab key for in Python?
You can use the tab key for "code completion". While you type, the editor makes a best guess as to what you want to type, and pressing the Tab key will insert the best guess into your code.
what is printed by the following statements alist = [4, 2, 8, 6, 5] temp = alist.pop(2) temp = alist.pop() print(alist)
[4,2,6]
what is printed by the following statements alist = [4, 2, 8, 6, 5] alist.append(True) alist.append(False) print(alist)
[4,2,8,6,5,true,false]
what is printed by the following statements alist = [4, 2, 8, 6, 5] alist.insert(2, True) alist.insert(0, False) print(alist)
[false,4,2,true,8,6,5]
append
adds a item to the end of a list
object
an instance of a class
def
header-which identifies the section of code as a function
what identifies the part of the code that executes whenever the function is called
indent
insert
inserts a new item at the position given
reverse
modifies a list to be in reverse order
sort
modifies a list to be sorted
(self)
the argument that is provided for the function to use
get_first_name()
the name of the function, or class, that may be used to call the function
return
the name of the function, or class, that may be used to call the function
File Management
the process of organizing files and folders; naming appropriately, using folders, etc.
What can you determine in Python with a modulo?
you can use the modulo operator (%) in Python to determine evenness or oddness by finding the result of mod 2. If the result is 0, the number is even; if the result is 1, the number is odd.