Looks like no one added any tags here yet for you.
Two types of files
Text file (contains data that's been encoded as text)
Two ways to access data stored in file
Sequential access (file read sequentially from beginning to end, can't skip ahead)
Direct access (can jump directly to any piece of data in the file)
open function
used to open a file; creates a file object and associates it with a file on the disk
file_object = open(filename, mode)
Mode
string specifying how the file will be opened (r=reading, w=writing, a=appending)
Method
a function that belongs to an object
ex. file_variable.write(string)
close using the .close() method
read method
file object method that reads entire file contents into memory
readline method
file object method that reads a line from the file
read position
marks the location of the next item to be read from a file
when open file with 'w' mode, if the file already exists
it is overwritten
dictionary
object that stores a collection of data (each element consists of a key and a value)
-key must be an immutable object
-dictionaries are mutable
general format for retrieving value from dictionary
dictionary[key]
dictionaries are mutable, to add a new key-value pair:
dictionary[key] = value
len function
used to obtain number of elements in a dictionary
to create an empty dictionary
{}
or built-in function dict ()
items method
returns all the dictionaries keys and associated values
clear method
deletes all the elements in a dictionary, leaving it empty
get method
gets a value associated with a specified key from the dictionary
keys method
returns all the dictionaries keys as a sequence
pop method
returns value associated with specified key and removes that key-value pair from the dictionary
values method
returns all the dictionaries values as a sequence
popitem method
returns a randomly selected key=value pair and removes that key-value pair from the dictionary
Key
always on the left side (always a text/in quotes)
value
always on right (can be any Python object)
list needs ______ value, dictionary needs _____ value
index , key
KeyError
didn't find a match for your key/doesn't exist in dictionary
Will a key repeat in a dictionary?
No, keys are unique "updates the value"
Procedural Programming
writing programs made of functions that perform specific tasks
Object-oriented programming
focused on creating objects
Object
entity that contains data and procedures
Objects have methods and attributes
procedures are methods, data is attributes
Data hiding
objects data attributes are hidden from code outside the object (access restricted to the object's method)
Object reusability
the same object can be used in different programs
an instance
something that belongs to a class/an object created from a class
Class
code that specifies the data attributes and methods of a particular type of object
Class definition
set of statements that define a class's methods and data attribute
"self" parameter
required in every method in the class-references specific object that the method is working on (always first parameter that we need)
objects state
the values of the object's attribute at a given moment
Mutator method
(set method) allows you to change the value of an attribute
Accessor method
(get method) returns value of an attribute
Instance attribute
belongs to a specific instance of a class (if many instances of a class are created, each would have its own set of attributes)
passing objects as arguments
when you pass an object as an argument, you are actually passing a reference to the object
UML diagram
standard diagrams for graphically depicting object-oriented systems
Inheritance
used to create an "is a" relationship between classes, exists when one object is a specialized version of another object
Superclass
base class/general class
Subclass
derived/specialized class (extended version of superclass)
(superclass name is placed in parentheses after subclass name)
polymorphism
an objects ability to take different forms
Initializer method
calls initializer method of superclass and then initializes unique data attributes (superclass cannot access methods in subclass, BUT subclass can access any methods in superclass) (cannot create a subclass without first creating the superclass)
Hidden attributes
are not passed on in inheritance (if you hide it in the parent it won't be passed)
User Interface
the part of the computer with which the user interacts
Command line interface
displays a prompt and the user types a command that is then executed
Graphical User Interface (GUI)
allows users to interact with a program through graphical elements on the screen; event-driven (the user determines the order in which things happen)
tkinter module
allows you to create simple GUI programs
Widget
graphical element that the user can interact with or view
__init__method
builds the GUI
Label widget
displays a single line of text in a window
pack method
determines where a widget should be positioned and makes it visible when the main window is displayed
Frame widget
container that holds other widgets
Button widget
widget that the user can click to cause an action to take place
Info dialog box
a dialog box that shows information to the user
Quit button
create a Button, set the root widgets destroy method as callback function
Entry widget
rectangular area that the user can type text into
IntVar class can be used along with
Radiobutton widgets
The readline method
uses a sentinel when the end of a file is reached
encapsulation
a self contained unit combining data and code into single objects