Python For Real Flashcards
parameter
a named variable that passes through a function’s argument(s)
module
a file that contains definitions—including variables and functions—that you can use once it is imported
generic import
Hint: It’s helpful to print the contents of a newly imported module you’re unfamiliar with to make sure you’re not reusing its content names.
simply calling a module in its entirety allowing access to all of its contents but forcing you to include the module name before each owned function (which may help by allowing you to write similarly named functions and variables)
import math
math.sqrt(#)
function import
calls a single function from a module freeing you from having to prefix each use of the function with the module name
from module import function
universal import
Hint: It’s common for professional developers to import only the functionality that is required, and not blindly import an entire module when there is no good reason to do so.
calling everything from a module and allowing you to call its contents without a module name prefix which can potentially cause the hazard of overlapping names if you write a similar function or variable yourself
from module import *
argument
the process(es) defined in a function such as multiplying the parameter(s) by 3 then returning the result
return
command to return values or to exit the method without returning a value
list
a datatype you can use to store a collection of different pieces of information as a sequence under a single variable name (the sequence starts at 0, not 1)
list_name = [item1, item2, item3, etc.]
index
address that identifies an individual item’s place on a list (starting with 0, not 1) allowing you access by including it’s identifier in brackets attached to and immediately following the list name
index_name[3]
slice
calls forth a section of a list or string beginning with the first included index item and ending with but not including the last index number written
index_name[3:9]
.index()
searches an index for the first instance of the parameters input and returns the numerical location
example.index(wanted)
.insert()
allows you to add an item to a list as well as its new specific index location if provided first in the parentheses subsequently shifting all other list items down the list in terms of index numbering (keep in mind that the number doesn’t have to be a digit, it can be the numerical content of another variable)
example.insert(#, new_item)
for loop
assigns to a variable (for variable) the value of a designated list (in list_name) whose contents will be used one at a time in the following code (:)
for variable in list_name:
code
.append()
adds a new variable to the end of your list
list_name.append(variable)
.sort()
alphabetizes the contents of your chosen list
list_name.sort()
dictionary
similar to a list whose contents can be called by using keys rather than index numbers (great for things phone books & login pages) and is distinguished by declaring its contents within curly brackets even though its information is still manipulated using standard brackets
dict_name = {"k1":v1, "k2":v2, etc} dict_name["key_name"] = new_value
key-value pair
components of a dictionary item starting with the string to identify the item, colon, then the contents inside curly brackets
dict_name = {“key”:contents of item}
del
deletes the chosen item from a dictionary
del dict_name[“key_name”]
.remove()
removes the first instance of the specified item from the list without returning anything using the actual contents in quotation marks rather than an index location
list_name.remove(“item”)
.pop()
removes and returns the contents of the list item at the index number/identifier you provide in parentheses
list_name.pop(index)
del()
removes the contents of a list at the index location provided without returning anything
del(list_name[index])
range()
function which returns a list of numbers from start up to (but not including) stop, each time increasing by step (start defaults to 0 and step defaults to 1)
range(start_num, stop_num, step_num)
.join()
function that returns a string of the list argument’s elements (a sequence of strings) separated by the string named in the prefix
separator.join(string_list)
\
escape character: also allows you to continue a specific line of code on the next line
break
a one-line statement that means “exit the current loop”