CSE Crowson MSU Exam 3

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/48

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

49 Terms

1
New cards

The write() method immediately writes data to a file

False

2
New cards

file.write() method

writes a string argument to a file

3
New cards

a mode:

indicates how a file is opened

4
New cards

most used modes are:

'r' (read), 'w' (write)

5
New cards

mode 'a':

Open the file for appending

6
New cards

mode 'r'

Open the file for reading

7
New cards

mode 'w':

Open the file for writing.

8
New cards

The flush() file method can:

force the interpreter to flush the output buffer to disk

9
New cards

The statement f.write(10.0) always produces an error

True

10
New cards

The flush() method (and perhaps os.fsync()) forces the output buffer to write to disk

True

11
New cards

binary data

data stored as a sequence of bytes

12
New cards

bytes object

a sequence of single byte values

13
New cards

For a program run as "python scriptname data.txt", what is sys.argv[1]?

data.txt

14
New cards

A script "myscript.py" has two command line arguments, one for an input file and a second for an output file. Type a command to run the program with input file "infile.txt" and output file "out".

> python myscript.py infile.txt out

15
New cards

When using a with statement to open a file, the file is automatically closed when the statements in the block finish executing.

True

16
New cards

file.close() method

closes the file

17
New cards

file.write() method

writes a string argument to a file

18
New cards

the process of responding to unexpected or unwanted events and errors during execution

exception handling

19
New cards

EOFerror

input() hits an end-of-file condition (EOF) without reading any input

20
New cards

KeyError

A dictionary key is not found in the set of keys

21
New cards

ZeroDivisionError

Division by zero

22
New cards

ValueError

Invalid value

23
New cards

IndexError

Accessing an index that is out of range

24
New cards

Set:

unordered linear data type, every element is unique, using curly braces

25
New cards

set.intersection

Returns a new set containing only the elements in common between set and all provided sets.

26
New cards

set.union

Returns a new set containing all of the unique elements in all sets.

27
New cards

set.difference

Returns a set containing only the elements of set that are not found in any of the provided sets

28
New cards

len(set)

Find the length (number of elements) of the set.

29
New cards

set1.update(set2)

Adds the elements in set2 to set1.

30
New cards

set.add(value)

Adds value into the set.

31
New cards

set.remove(value)

Removes value from the set. Raises KeyError if value is not found.

32
New cards

set.pop()

Removes a random element from the set.

33
New cards

set.clear()

Clears all elements from the set.

34
New cards

A dictionary entry is accessed by placing a key in curly braces { }.

False

35
New cards

Dictionary entries are ordered by position.

True

36
New cards

dict[ ] =

adds elements to a dictionary or overwrites a value

37
New cards

When you open a file in write mode:

it automatically erases the file contents

38
New cards

When you write to a file that does not exist:

it creates that file

39
New cards

What are CSV files?

text based file that uses commas to separate data items

40
New cards

What is the purpose of exception handling?

To handle errors gracefully so the program does not crash.

41
New cards

Where do errors occur?

Inside the try block

42
New cards

If Python finds a error in the try block:

python quits running the code and moves the except block

43
New cards

What does the except block do?

It prints a message to the user stating an error has occurred

44
New cards

What are the two primary components to a class?

methods and attributes

45
New cards

What is the responsibility of the _init_ method?

initializes values to attributes

46
New cards

What is the self method?

referring the instance of class, calling the method

47
New cards

How do you access the attributes of a class?

Using a dot operator

48
New cards

What is better than accessing the attributes of a class?

using setters and getters

49
New cards

What is the difference between a tuple and list?

Tuples are immutable