Exam 1 Flashcards
variables
named storage bins that hold onto values
assignment statements
a line of code that assigns a value to a variable
float
numbers with decimals
float()
integers
numbers without decimals
int()
string
text
str()
comments
used to explain code
#
variable naming conventions
- cannot start with numbers
- no numbers after _
- all lowercase
expression
any mathematic calculation found on the right side of a statement
ex: x + 3
//
integer division
%
remainder division
input()
accepts a value from the user (always stored as a string)
opening a file
with open(“file_name”, “r”) as infile:
reading a file line
infile.readline()
skipping a file line
next(infile)
plotting import statement
import matplotlib.pyplot as plt
main plotting functions (5)
Plt.plot(x, y, marker)
Plt.title(title)
Plt.xlabel(xlabel)
Plt.ylabel(ylabel)
Plt.show( )
boolean
a data type that can only store 2 values (True or False)
comparison operators
> , <, <=, >=, ==, !=
for loop
for item in sequence:
range function
range(start, stop, step)
not inclusive of “stop”
accumulator loops
initialize, iterate, update, report
indexing
list[start:stop:step]
not inclusive of “stop”
concatenating lists
list + list
adding to lists
list.append
length function
len()
split function
string.split()
splits a string on a space or other specified character and creates a list
replace function
string.replace(a, b)
replaces all a with b
strip function
string.strip()
removes all white space
lower case / capital function
string.upper / string.lower
checking for all numbers in a string
string.isdigit()
checking for all letters in a string
string.isalpha()
insert in a list
list.insert(position, element)
remove from a list
list.remove(element)
remove the last element from a list
list.pop()
finding the index number
list.index(element)
while loop
while condition:
reading a CSV
- Create an empty list
- Use the with open function
- For row in file:
a. List.append(row.strip())