Dictionaries
(def., & 6 properties)
list (def. & 3 properties)
sets
(def., how created, how to add objects)
tuple
(def./how to create, prop., when to use)
definition
properties
when to use
when to use a dictionary ( 1 )
when to use a list ( 2 )?
index a string, slice a string, index nested string
index: mystring[0] , mystring[7], mystring[-1]
slice: mystring[2:], mystring[3:7], mystring[:3]
nested string: mystring[0][1]
How to format floating point numbers within a string with the .format( ) method
result = 1000/777
print(“The result was { r : 1.3f}”.format(r = result))
String Concatenation & Repitition
(addition & multiplication)
first\_last = 'first name' + ' ' + 'last name' letter = 'z', z \* 10 returns 10 z's
Setting Data Types in Python
(strings, integers, floats, complex)
string: quotation marks (“ “), or str( )
integer: x = 20 or x = int(20)
float: x = 20.5 or x = float(20.5)
complex: x = 20j or x = complex(20j)
unpacking for string, list, & dictionaries
(how to perform)
unpacking with star notation
def: extract each element from string, tuple, dictionary
Unpacking with star notation:
the left side assignemnt must be in a tuple or list
*a, = 1, 2 returns: a = [1, 2]
a, *b = 1, 2, 3 returns: a = 1 , b = [2, 3]
*a, b = 1, 2, 3 returns: a = [1, 2] , b = 3
*a, b, c, d = 1, 2, 3 returns:
a = [], b = 1, c = 2, d = 3
Slice Notation
(syntax and what datasets they are used for)
used for list, strings, & tuples
list [start : stop : step]
What it a deque in Python?
a deque is a special data strucure in python for implementing stacks and queues
the deque is pronounced “deck” and is short for “double-ended queue”
produces O(1) performance in either direction, more efficient than list with O(n) performance