Comp Sci Exam 2

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/98

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.

99 Terms

1
New cards

Positional Arguments

Arguments that must be passed in the same order in which the corresponding parameters are defined

2
New cards

Keyword Arguments

used to specify the parameter name with values in a function call, making the order irrelevant, and MUST be written to the right of all the positional arguments

3
New cards

Variable Length Arguments

*args

used in combination with regular arguments and MUST be placed after all the regular arguments

Ex: def variable_sum(first_arg,*args):

4
New cards

Variable-Length Keyword Arguments

**kwargs

used in the parameter list to pass a variable number of keyword arguments

5
New cards

Local Variables

variables defined insdie a fucntion and their scope is limited to that function

6
New cards

Global Variables

variables outside any function and accessible throughout the program

7
New cards

“global” keyword

used to modify the value of a global variable by defining it

8
New cards

Inner (nested) Function

a function defined inside another function and dependent on the outer function calling it to execute

9
New cards

“nonlocal” keyword

keyword used to affect inner function by changes to the outer function

10
New cards

Hidden variable

if a variable with the same name as the global variable is present in the outer function the global variable or varibale in outer function

11
New cards

Lambda function

lambda arguments : expression

small one-line functions that does not use keywords and can take any number of arguments but only one expression

12
New cards

Importing modules

import module_name

to use a user-written model and can use the keyword “as” to abbreviate module name

13
New cards

Import Specfic elements

from module_name import func

use the keyword “from” to import specific element

14
New cards

if _name_ == ‘_main_’

will execute only if the module is run as a standalone script but NOT when the module is imported ti another script

used when you want a module to define reusable values/functions while also containing runnable code

15
New cards

Recursion

mathematical and programming concept, meaning that a function calls itself

solves a problem by breaking it down into simpler and more manageable parts

16
New cards

Recursion Piece One

one or more base cases; simplest cases that the function already knows how to solve

Ex: if n==0:

            return 1

17
New cards

Recursion Piece Two

recursive steps, slightly simpler or smaller versions of the orginal problem

Ex: return n*factorial(n-1)

18
New cards

Recursion Terminate

terminates when the sequence of smaller problems equals or converges to the base case

19
New cards

Iteration Control Statement

repetition (loops)

20
New cards

Iteration Repetition Involved

repeated loop body

21
New cards

Iteration Termination

when the loop condition fails

22
New cards

Iteration Performance

usually quicker than recursion

23
New cards

Recursion Control Statement

conditional statements (branching aka if,elif, and else)

24
New cards

Recursion Rpeetition Involved

repeated function calls

25
New cards

Recursion Performance

singnificant overhead (run time) due to repeated function calls

26
New cards

Accesing Characters in a String

string_name[index]

27
New cards

String Slices

string_name[start:step]

a segement of a string

28
New cards

len() function strings

reutnrs the number of characters in the string

29
New cards

the ‘in’ operator string

a boolean operator that takes two stirngs and returns True if the first operatorappears as substring in the second

Ex: ‘a’ in ‘banana’ → True ; ‘seed’ in ‘banana’ → False

30
New cards

String Compariosn == and !=

check if two strings are equal

31
New cards

String Comparison >,<,>=, and <=

use lexicographical comparison of strings

32
New cards

Lexicographical comparison

comparing string based on the order of thier elements; comparison stops at the first position where elements differ

33
New cards

Python String Formatting

f “string { }”

34
New cards

Escpae Charaters

a baclash followed by character you want to insert

can insert special characters in a string

Ex: print(“He said to me, “\How are you?\” with a smile. ”)

35
New cards

Quote

\’ or \”

36
New cards

Backlash

\\

prints a \ in a string

37
New cards

New Line

\n

38
New cards

Carriage Return

\r

overwrite the existing content on that same line from the beginning, effectively replacing the previously printed characters

39
New cards

Tab

\t

40
New cards

Backspace

\b

deletes character it follows a in string

41
New cards

Slice Assignment (List)

use the slice operator on the left side of an assignment to update multiple lsit elements

42
New cards

Deleting List Elements

use ‘del’ operator to delete one or a slice of list elements

43
New cards

List Operations ‘+’

The operator combines the list to form a new list

[1,2,3] + [4,5,6] → [1,2,3,4,5,6]

44
New cards

List Operator ‘*’

the operator returns a list that repeats the original list a given number of times

[2,4,6]*3 → [2,4,6,2,4,6,2,4,6]

45
New cards

len() fucntion in list

function returns the number of elements in the list

len([‘spam’,2.0,5,[10,20]])==4

46
New cards

min() and max()

return the min and max elements of a list respectively

will say an error if the list has an items of mixed type

47
New cards

sum () function list

calculates the summation of numbers in the list

sum([2.0, 5, 10, 20]) → 37.0

48
New cards

List updating

slice assignment meaning the orginal and updated lists are the same object

49
New cards

id() function and ‘is’ operator

check if two variables refer to the same object

50
New cards

List Comprehension

newlist = [espression for item in oldest if condition]

offers a concise syntax to create a new list based on the items of an existing list

51
New cards

slicing list

creates a new list

52
New cards

slice assingment lists

modifies the exisitng list

53
New cards

Multi-Dimensional Lists

list_name[row_index][column_index]

Ex: a[2][-4]==8

54
New cards

Multi-dimnensional list comprehension

creates a m x n matrix where m is the number of rows and n is the number of columns

55
New cards

Tuples

a sequence of values where values can be ANY type, values are ordered, and duplicate values are allowed

56
New cards

Tuple Operators Invalid

can NOT add or remove from a tuple once created and can NOT append to or extend a tuple

57
New cards

Tuple Operators Valid

‘+’ and ‘*’ operators

len(), sum(), max(), min() functions

compare lexicogrpahically

‘del’ 

58
New cards

sorted()

sort the tuple alphabetically

59
New cards

Tuple Assignment

can assign multiple values to multiple variables all on one line (unpacking)

Ex: (a,b,c,d) = (1,2,’xyz’,True)

60
New cards

List Mutability

mutable (can be modified after creation)

61
New cards

List Syntax

defined using square brackets [ ]

62
New cards

List Methods

has more built in methods (ex: append, remove)

63
New cards

List Use Cases

suitable for collections of items that may change

64
New cards

LIst Memory Usage

consumes more memroy due to flexibility

65
New cards

List Iteration

iteration can be slightly lower

66
New cards

List Performance

slower due to dynamic size and mutability

67
New cards

Tuple Mutability

immutable (cannot be modified after creation)

68
New cards

Tuple Syntax

defined using parentheses ( )

69
New cards

Tuple Methods

fewer built in methods

70
New cards

Tuple Use Cases

ideal for fixed collections of items

71
New cards

Tuple Memory Usage

consumes less memory due to immutability

72
New cards

Tuple Iteration

iteration faster due to immutability

73
New cards

Tuple Performance

faster due to static size and immutability

74
New cards

Sets

a collection of items enclosed by curly brackets { }

and are unordered so can NOT be referred to by index and duplicate vlaues are NOT allowed

Ex: fruits= {“apple”, “banana”, “cherry”}

75
New cards

Add Set Items

add() function to add one item to a set

update() function to add items from another set, lidt or tuple to a set

both in place changes

76
New cards

Delete Set Items

remove() and discard() fucntions to remove an item

77
New cards

Empties set

clear() function

78
New cards

‘del’ opetator set

deletes set completely

79
New cards

List to Tuple Conversion

list1=[0,1,2]

tuple(list1) → (0,1,2)

80
New cards

Set Conversion to other Data Structures

set() function 

Ex: x = set((“apple”, “banana”, “cherry”)) or 

n = set([0,1,2,3,4])

81
New cards

Set Method difference()

returns the difference between two or more sets

82
New cards

Set Method intersection()

returns the interaction of two oe more sets

83
New cards

Set Method isdisjoint()

returns whether two sets have an interaction or not

84
New cards

Set Method issubset()

returns whether another set contains this set or not

85
New cards

Set Method issuperset()

returns whether this set contains another set or not

86
New cards

Set Method symmetric_difference()

returns the symmetric differneces of two sets

87
New cards

Set Method union()

reutrns the union of sets

88
New cards

String Modifier :<

left aligns the result

89
New cards

String Modifier :>

right aligns the result

90
New cards

String Modifier :^

center aligns the result

91
New cards

String Modifier :+

use a plus sing to indicate if the result is positive or negative

92
New cards

String Modifier :

use a space to insert an extra space before positive numbers and aminus sign before negative numbers

93
New cards

String Modifier :,

use a underscore as a thousand separator

94
New cards

String Modifier :b

binary format

95
New cards

String Modifier :d

decimal format

96
New cards

String Modifier :e or :E

scientific format

97
New cards

String Modifier :f

fix point number format

98
New cards

String Modifier :%

percentage format

99
New cards

Iterable

an object that can be looped over or ‘iterated’ through one element at a time

capable of returning its member value one by one