Test 3 Chapters 7, 8, and 9 Flashcards
Using floating-point numbers can lead to arithmetic errors because floating-point numbers
approximate values
To read a list of lists that’s stored in a binary file, you use
the load() method of the pickle module
A binary file is like a text file in all but one of the following ways. Which one is it?
A binary file stores numbers with binary notation.
A method for creating an object in a class.
constructor
CSV File
is a type of text file that stores multiple values in each line (.csv)
The csv module is a standard module so you don’t need to import it
Which of the following is not true about a CSV file?
Decimal Class
a decimal object that stores a decimal number
Exact Value
exact value that yields expected results
Except Clause
except is used to catch and handle the exception(s) that are encountered in the try clause.
Exception
occurs when you try to open a file that does not exist and the program crashes
exit()
To cancel the execution of a program in the catch clause of a try statement, you can use the
ceil()
returns ceiling value of x i.e., the smallest integer not less than x.
FileNotFoundError
If a program attempts to read from a file that does not exist, which of the following will catch that error?
Finally Clause
a part of a try block that is executed no matter how the try block is exited
float(data)
method is used to return a floating point number from a number or a string.
int(data)
method is used to return an integer point from a number.
Floating-Point Error
It’s a problem caused when the internal representation of floating-point numbers, which uses a fixed number of binary digits to represent a decimal number
Floating-Point Number
any number with a decimal point
floor()
returns floor of x i.e., the largest integer not greater than x.
To define a variable named number that contains 123.4567 as a decimal number, not a floating-point number, which block of code would you use?
from decimal import Decimal
number = Decimal(123.4567)
Immutable
cannot be changed
Index
refers to a position within an ordered list. Python strings can be thought of as lists of characters; each character is given an index from zero (at the beginning) to the length minus one (at the end).
lc.setlocale
opens access to the POSIX locale database and functionality. The POSIX locale mechanism allows programmers to deal with certain cultural issues in an application, without requiring the programmer to know all the specifics of each country where the software is executed.
Locale Module
part of Python’s internationalization and localization support library. It provides a standard way to handle operations that may depend on the language or location of a user.
Math Module
provides access to the mathematical functions defined by the C standard.
Mutable
can be changed
New Line
\n it is used to indicate the end of a line of text
OS Error
a built-in exception in Python and serves as the error class for the os module, which is raised when an os specific system function returns a system-related error, including I/O failures such as “file not found” or “disk full”.
Pickle
generally known as serializing an object, writing a python object to a binary file
Pickle Module
makes it easier to work with binary files, it automates the process of storing an object in a binary file
Print Format
prints the specified message to the screen, or other standard output device. The message can be a string, or any other object, the object will be converted into a string before written to the screen.
print(data).format
give placeholders an explicit positional index.This allows for re-arranging the order of display without changing the arguments.
Raise Statement
To throw an exception with Python code, you use the
read()
returns the specified number of bytes from the file.
readline()
method returns one line from the file.You can also specified how many bytes from the line to return, by using the size parameter.
reader()
s used to read the file, which returns an iterable object.
readlines()
returns a list containing each line in the file as a list item.
Repitition Operator
makes multiple copies of a tuple and joins them all together.
Scientific Notation
a method for expressing a given quantity as a number having significant digits necessary for a specified degree of accuracy, multiplied by 10 to the appropriate power, as 1385.62 written as 1.386 × 103.
setlocale()
modifies the locale setting for the category.
sys module
provides functions and variables used to manipulate different parts of the Python runtime environment.
Text File
stores all of its data as characters and each line ends with a new line character
Try Clause
all statements are executed until an exception is encountered. except is used to catch and handle the exception(s) that are encountered. Else lets you code sections that should run only when no exceptions are encountered
Try Statement
you code any statements that may throw an exception in the try clause
type()
either returns the type of the object or returns a new type object based on the arguments passed
with open()
returns a file object, which has methods and attributes for getting information about and manipulating the opened file.
With Statement
used to open a file object thats only available for its block of statements