Introduction to Computer Programming - Test 3 Review

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

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.

50 Terms

1
New cards

What are tuples

a collection of data that is immutable

2
New cards

How to create a tuple

coordinates = (1, 2, 3, 4)

3
New cards

What are named tuples

they allow the programmer to define a new data type that consist of named attributes

4
New cards

How to create a named tuple

name1 = namedtuple("name1", ["detail1", "detail2", "detail3"])

5
New cards

What is a set

an unordered collection of unique elements

6
New cards

How to create a set

nums1 = set([1, 2,3])

7
New cards

How to create a set literal

nums1 = {1, 2, 3}

8
New cards

Does indexing in sets work?

No, because the sets are unordered

9
New cards

How to find the number of elements in a set

len(set)

10
New cards

How to add elements in set2 to set1

set1.update(set2)

11
New cards

How to add value into the set

set.add(value)

12
New cards

How to remove value from the set

set.remove(value)

13
New cards

How to remove a random element from the set

set.pop()

14
New cards

How to clear all elements from the set

set.clear()

15
New cards

What are dictionaries

they contain references to objects as key-value pairs

16
New cards

Syntax for creating dictionary

dict(reference="pair", reference1="pair2")

dict([("reference", "pair"), ("reference2, "pair2")])

17
New cards

how to retrieve the value associated with a key

my_dict[key]

18
New cards

how to add an entry

my_dict[key] = value

19
New cards

how to delete the key from the dictionary

del my_dict[key]

20
New cards

how to test for existence of key in my_dict

key in my_dict

21
New cards

how to remove all items from the dictionary

my_dict.clear()

22
New cards

How to read the value of the key from the dictionary

my_dict.get(key, default):

23
New cards

How to merge dictionary1 with dictionary2

my_dict.update(my_dict2)

24
New cards

my_dict.pop(key, default)

removes and return the key value from the dictionary

25
New cards

How to return a view object that only yields (key, value)

dict.item()

26
New cards

How to return a view object that yields dictionary keys

dict.keys()

27
New cards

How to return a view object that yields dictionary values

dict.values()

28
New cards

How to open a file

open()

29
New cards

How to close a file

file.close()

30
New cards

how to return the file contents as a string

file.read()

31
New cards

How to return a list of strings

file.readlines()

32
New cards

How to write a string argument to a file

file.write()

33
New cards

How to open the file for reading

open("file_name", "r")

34
New cards

How to open the file for writing

open("file_name", "w")

35
New cards

How to open the file for appending

open("file_name", "a")

36
New cards

What is error-checking code

code that a programmer introduces to detect and handle errors that occur while the program executes

37
New cards

What is a try block

code that could be potentially ran

38
New cards

What is an except block

any error that occur, the code is run through here

39
New cards

What is EOFError

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

40
New cards

What is KeyError

a dictionary key is not found in the set of keys

41
New cards

What is ZeroDivisionError

cannot be divided by zero

42
New cards

What is ValueError

invalid value

43
New cards

What is IndexError

index is out of bounds

44
New cards

What is raise

used to detect an error and cause an immediate exit from the try block

45
New cards

What is a class

user defined type of object containing groups of related variables and functions

46
New cards

What is attribute

the data and behavior of the class

47
New cards

What is an instance

an individual object of the given class

48
New cards

How to create a class?

class ClassName:

def __init__(self):

self.attribute1

self.attribute2

49
New cards

What is method

the function defined within a class

50
New cards

How are attributes accessed?

through dot notation