Python Midterm Prep Multiple Choice (copy)

5.0(1)
studied byStudied by 23 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/63

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 4:04 PM on 10/19/23
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

64 Terms

1
New cards

Two types of files

Text file (contains data that's been encoded as text)

2
New cards

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)

3
New cards

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)

4
New cards

Mode

string specifying how the file will be opened (r=reading, w=writing, a=appending)

5
New cards

Method

a function that belongs to an object

ex. file_variable.write(string)

close using the .close() method

6
New cards

read method

file object method that reads entire file contents into memory

7
New cards

readline method

file object method that reads a line from the file

8
New cards

read position

marks the location of the next item to be read from a file

9
New cards

when open file with 'w' mode, if the file already exists

it is overwritten

10
New cards

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

11
New cards

general format for retrieving value from dictionary

dictionary[key]

12
New cards

dictionaries are mutable, to add a new key-value pair:

dictionary[key] = value

13
New cards

len function

used to obtain number of elements in a dictionary

14
New cards

to create an empty dictionary

{}

or built-in function dict ()

15
New cards

items method

returns all the dictionaries keys and associated values

16
New cards

clear method

deletes all the elements in a dictionary, leaving it empty

17
New cards

get method

gets a value associated with a specified key from the dictionary

18
New cards

keys method

returns all the dictionaries keys as a sequence

19
New cards

pop method

returns value associated with specified key and removes that key-value pair from the dictionary

20
New cards

values method

returns all the dictionaries values as a sequence

21
New cards

popitem method

returns a randomly selected key=value pair and removes that key-value pair from the dictionary

22
New cards

Key

always on the left side (always a text/in quotes)

23
New cards

value

always on right (can be any Python object)

24
New cards

list needs ______ value, dictionary needs _____ value

index , key

25
New cards

KeyError

didn't find a match for your key/doesn't exist in dictionary

26
New cards

Will a key repeat in a dictionary?

No, keys are unique "updates the value"

27
New cards

Procedural Programming

writing programs made of functions that perform specific tasks

28
New cards

Object-oriented programming

focused on creating objects

29
New cards

Object

entity that contains data and procedures

30
New cards

Objects have methods and attributes

procedures are methods, data is attributes

31
New cards

Data hiding

objects data attributes are hidden from code outside the object (access restricted to the object's method)

32
New cards

Object reusability

the same object can be used in different programs

33
New cards

an instance

something that belongs to a class/an object created from a class

34
New cards

Class

code that specifies the data attributes and methods of a particular type of object

35
New cards

Class definition

set of statements that define a class's methods and data attribute

36
New cards

"self" parameter

required in every method in the class-references specific object that the method is working on (always first parameter that we need)

37
New cards

objects state

the values of the object's attribute at a given moment

38
New cards

Mutator method

(set method) allows you to change the value of an attribute

39
New cards

Accessor method

(get method) returns value of an attribute

40
New cards

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)

41
New cards

passing objects as arguments

when you pass an object as an argument, you are actually passing a reference to the object

42
New cards

UML diagram

standard diagrams for graphically depicting object-oriented systems

43
New cards

Inheritance

used to create an "is a" relationship between classes, exists when one object is a specialized version of another object

44
New cards

Superclass

base class/general class

45
New cards

Subclass

derived/specialized class (extended version of superclass)

(superclass name is placed in parentheses after subclass name)

46
New cards

polymorphism

an objects ability to take different forms

47
New cards

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)

48
New cards

Hidden attributes

are not passed on in inheritance (if you hide it in the parent it won't be passed)

49
New cards

User Interface

the part of the computer with which the user interacts

50
New cards

Command line interface

displays a prompt and the user types a command that is then executed

51
New cards

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)

52
New cards

tkinter module

allows you to create simple GUI programs

53
New cards

Widget

graphical element that the user can interact with or view

54
New cards

__init__method

builds the GUI

55
New cards

Label widget

displays a single line of text in a window

56
New cards

pack method

determines where a widget should be positioned and makes it visible when the main window is displayed

57
New cards

Frame widget

container that holds other widgets

58
New cards

Button widget

widget that the user can click to cause an action to take place

59
New cards

Info dialog box

a dialog box that shows information to the user

60
New cards

Quit button

create a Button, set the root widgets destroy method as callback function

61
New cards

Entry widget

rectangular area that the user can type text into

62
New cards

IntVar class can be used along with

Radiobutton widgets

63
New cards

The readline method

uses a sentinel when the end of a file is reached

64
New cards

encapsulation

a self contained unit combining data and code into single objects