Anda di halaman 1dari 2

1.

Return Value
a. What happens when you have a function that returns the same number as the
input. Is the output still the same object as the input?
2. Generators
a. Functions that generate other functions in a list, stopping the generation once a
yield function is reached.
i. Yield returns the items one a time, and then goes back to the beginning of
the loop
b. It makes a list of values of the function from 0 to n
3. Read and Writing to Files
a. If you want to write to a file, you need to write directly to it
b. There is a buffer, you cannot edit a file in the text editor unless the file.
i. Its a lot faster to write to a buffer than it is to write to memory directly
ii. So what happens is that the buffer is written to, and then when the file is
close() it writes the entire buffer to memory at once.
4. Error Handling
a. Try and Except
i. Try:
1. F2 = open(somefile.txt,r)
ii. Except FileNotFoundError:
1. print(No such file)
b. Another common error in file opening is that you try to write to a r file or read a
w file. Unsupported Operation exception.
c. Good idea to add multiple except blocks to handle multiple errors
d. Common exception types
i. TypeError vs ValueError
1. TypeError is performing an operation that is not defined for the set
combination of datatypes
2. ValueError is when an operation is applied to data of the
inappropriate type.
ii. KeyError
1. No value associated with the key
2. Can be handled by making a key for the thing in the except block
iii. IndexError
1. Index is out of range of the array
5. Object Oriented Program
a. A class is an outline or a blueprint for a group of objects
b. An instance is an object created due to those specifications
c. Instances can have their own individual values, are parameterized
d. Attributes, two kinds of attributes
i. Instance variables: Stores variables, data in the instance
ii. Methods: Allows for functions to be applied to do the instance object
1. Has access to all of the data stored in the instance object
e. Self
i. Refers to the instance that the method is being called on
6. Encapsulation
a. Hiding implementation details
b. Methods provide the abstraction, it creates a distance between the programmer
and the class. It allows for the definition of natural looking functions
c. Programmer doesnt need to know all of the background programming to utilize
the class.
7. Polymorphism
a. Same operation applied to object of ALL different types
b. Implementing the same kinds of methods into different classes.
8.

Anda mungkin juga menyukai