Python Midterm Prep Multiple Choice (copy)

studied byStudied by 23 people
5.0(1)
Get a hint
Hint

Two types of files

1 / 63

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

64 Terms

1

Two types of files

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

New cards
2

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)

New cards
3

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)

New cards
4

Mode

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

New cards
5

Method

a function that belongs to an object

ex. file_variable.write(string)

close using the .close() method

New cards
6

read method

file object method that reads entire file contents into memory

New cards
7

readline method

file object method that reads a line from the file

New cards
8

read position

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

New cards
9

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

it is overwritten

New cards
10

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

New cards
11

general format for retrieving value from dictionary

dictionary[key]

New cards
12

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

dictionary[key] = value

New cards
13

len function

used to obtain number of elements in a dictionary

New cards
14

to create an empty dictionary

{}

or built-in function dict ()

New cards
15

items method

returns all the dictionaries keys and associated values

New cards
16

clear method

deletes all the elements in a dictionary, leaving it empty

New cards
17

get method

gets a value associated with a specified key from the dictionary

New cards
18

keys method

returns all the dictionaries keys as a sequence

New cards
19

pop method

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

New cards
20

values method

returns all the dictionaries values as a sequence

New cards
21

popitem method

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

New cards
22

Key

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

New cards
23

value

always on right (can be any Python object)

New cards
24

list needs ______ value, dictionary needs _____ value

index , key

New cards
25

KeyError

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

New cards
26

Will a key repeat in a dictionary?

No, keys are unique "updates the value"

New cards
27

Procedural Programming

writing programs made of functions that perform specific tasks

New cards
28

Object-oriented programming

focused on creating objects

New cards
29

Object

entity that contains data and procedures

New cards
30

Objects have methods and attributes

procedures are methods, data is attributes

New cards
31

Data hiding

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

New cards
32

Object reusability

the same object can be used in different programs

New cards
33

an instance

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

New cards
34

Class

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

New cards
35

Class definition

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

New cards
36

"self" parameter

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

New cards
37

objects state

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

New cards
38

Mutator method

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

New cards
39

Accessor method

(get method) returns value of an attribute

New cards
40

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)

New cards
41

passing objects as arguments

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

New cards
42

UML diagram

standard diagrams for graphically depicting object-oriented systems

New cards
43

Inheritance

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

New cards
44

Superclass

base class/general class

New cards
45

Subclass

derived/specialized class (extended version of superclass)

(superclass name is placed in parentheses after subclass name)

New cards
46

polymorphism

an objects ability to take different forms

New cards
47

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)

New cards
48

Hidden attributes

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

New cards
49

User Interface

the part of the computer with which the user interacts

New cards
50

Command line interface

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

New cards
51

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)

New cards
52

tkinter module

allows you to create simple GUI programs

New cards
53

Widget

graphical element that the user can interact with or view

New cards
54

__init__method

builds the GUI

New cards
55

Label widget

displays a single line of text in a window

New cards
56

pack method

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

New cards
57

Frame widget

container that holds other widgets

New cards
58

Button widget

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

New cards
59

Info dialog box

a dialog box that shows information to the user

New cards
60

Quit button

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

New cards
61

Entry widget

rectangular area that the user can type text into

New cards
62

IntVar class can be used along with

Radiobutton widgets

New cards
63

The readline method

uses a sentinel when the end of a file is reached

New cards
64

encapsulation

a self contained unit combining data and code into single objects

New cards

Explore top notes

note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 14 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 12 people
Updated ... ago
4.0 Stars(2)
note Note
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 26 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 3006 people
Updated ... ago
4.9 Stars(16)
note Note
studied byStudied by 8879 people
Updated ... ago
4.6 Stars(59)

Explore top flashcards

flashcards Flashcard73 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard124 terms
studied byStudied by 23 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard188 terms
studied byStudied by 32 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard148 terms
studied byStudied by 23 people
Updated ... ago
5.0 Stars(3)
flashcards Flashcard69 terms
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard25 terms
studied byStudied by 32 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard66 terms
studied byStudied by 1 person
Updated ... ago
5.0 Stars(1)
flashcards Flashcard52 terms
studied byStudied by 134 people
Updated ... ago
5.0 Stars(1)