CS 1104 Final Study Guide Latest 2023 Graded A+
CS 1104 Final Study Guide Latest 2023 Graded A+ object consists of some internal data items plus operations that can be performed on that data; more understandable, manageable, and properly-executing program built-ins automatically created by Python, like ints, strings, and functions class used to create a user-defined type of object containing groups of related variables and functions (EX: minutes and seconds in time); groups data and functions to form an object; use initial capitalization for class names attributes maintained by object; determines the data and behavior of the class; a name following a "." symbol instantiation operation performed by "calling" the class, using parentheses like a function call as in my_time = Time() instance created by an instantiation operation; an individual object of the given class; can create multiple instances of a class in a program, with each instance having different attribute values method functions that are also class attributes, can be referenced using dot notation (definition of method example: print_time(self, gmt)) constructor __init__ method, responsible for setting up the initial state of the new instance, single parameter "self" class object factory that creates instance objects class attribute shared amongst all of the instances of that class instance attribute can be unique to each instance, created using dot notation (EX: = 7.5 within a method, or = 7.5 from outside of the class' scope), can be also created/changed from outside the function scope instance object represents a single instance of a class class interface consists of the methods that a programmer calls to create, modify, or access a class instance _Class customization_ process of defining how a class should behave for some common operation; to customize a class, a programmer implements instance methods with special method names (EX: operator overloading) Rich Comparison Methods (6) __lt__(self, other) = less-than () __ge__(self, other) = greater-than or equal-to (=) __ne__(self, other) = not-equal to (!=) isinstance() function returns a True or False Boolean depending on whether a given variable matches a given type Methods for emulating numeric types __add__(self, other) = Add (+) memory allocation The process of an application requesting and being granted memory (All variables/objects in a Python application reside in allocated memory. An application cannot use memory that has not been allocated.) reference count an integer counter that represents how many variables reference an object; Python's garbage collector will deallocate objects with a reference count of 0 Error-checking code code that a programmer introduces to detect and handle errors that may occur while the program executes exception handling handling exceptional conditions (errors during execution); try and except constructs Multiple exception handlers can be added to a try block by adding additional except blocks and specifying the specific type of exception that each except block handles (for many types of errors) raise statement causes immediate exit from the try block and the execution of an exception handler finally clause of a try statement allows a programmer to specify clean-up actions that are always executed; always the last code executed before the try block finishes custom exception type usually defined by inheriting from the Exception class; not a function; usually end with error script file as input to the interpreter module a file containing Python code that can be imported and used by scripts, other modules, or the interactive interpreter; filename should end with ".py" (EX: filename = HTTP.py - import HTTP) dependency a module being required by another program module object a namespace that contains definitions from the module the importing process 1. es checked for HTTPServer 2. Module object created 3. HTTPServer added to es 4. HTTPServer code executed 5. HTTPServer added to importer's namespace from used to specify names to import from a module (EX: Import specific name from a module = from HTTPServer import address) __name__ global string variable automatically added to every module that contains the name of the module if __name__ == "__main__" if true, then the file is being executed as a script and the branch is taken. Otherwise, the file was imported and thus __name__ is equal to the module name reload() function can be used to reload and re-execute the changed module package directory that, when imported, gives access to all of the modules stored in the directory; must include a file called __init_.py open() function gets input from a file Iterating over each line of a file for ... in syntax () method writes a string argument to a file; Output is buffered, thus there may be a delay between calling the write method and data being written to the disk functions (path) - Splits a path into a 2-tuple (head, tail) s(path) - Returns True if path exists, else returns False e(path) - Returns True if path is an existing file, and false otherwise ze(path) - Returns the size in bytes of path () use when searching for specific files within a directory tree, and the exact path is unknown with statement used to open a file, execute a block of statements, and automatically close the file when complete comma separated values simple text-based file format that uses commas to separate data items, called fields derived class class that inherits the class attributes of another class, known as a base class, is-a relationship _multiple inheritance_ class can inherit from more than one base class _mixins_. classes that provide some additional behavior, by "mixin in" new methods, but are not themselves meant to be instantiated unit testing testing the individual components of a program (such as specific methods, class interfaces, data structures); unittest module
Written for
- Institution
- CS 1104
- Course
- CS 1104
Document information
- Uploaded on
- November 10, 2023
- Number of pages
- 8
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
cs 1104 final study guide latest 2023 graded a