week 8 intro to functions Flashcards

1
Q

def keyword

A

defines the function, the statement has color at the end and indented function body

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how can you customize a function?

A

add parameters so that numbers/vars can be passed as arguments in function call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

3 steps of making a function

A

1) define (fun name, parameters, body)
2) call (pass arguments)
3) execute (use parameters to compute result)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

find method

A

returns indices of first instance of a substring

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

string slicing

A

extracting certain characters (1st number inclusive, 2nd number exclusive)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

split method

A

splits string into list based on specified delimeter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

local variable

A

only exists in the function, the function is an ‘island’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

global variable

A

exists and modified in main code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

pass by value

A

parameters changed in function does not affect variables outside the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

return function

A

outputs value from function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

copy paste error

A

forgetting to modify code after pasting into new environment

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

return error

A

accidentally returning the wrong variable or forgetting to add return statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

unpacking

A

operation that allows statement to perform multiple assignments at once (ex: assigning tuple/list to variable in one line)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

index

A

integer matching specific position in ordered object (list, tuple, etc) starts at 0 and uses brackets to index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

slice notation

A

allows selection of multiple indices per list (using colons to select all before, after, or in between integers) negative numbers means a step back from the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

slicing operation

A

if you assign a slice to a var and reassign the original string, the slice var will stay the same

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

stride

A

step size to increment index

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

my_str[0:10:2]

A

0 to 10 in steps of 2 (every other, starting at 0)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

field width

A

defines minimum number of characters inserted in string, any extra space is padded with spaces to reach that minimum value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

{name:16}

A

field width of 16 characters

18
Q

alignment character

A

determines how value should be aligned within width of field

19
Q

<

A

left aligned

20
Q

>

A

right aligned

21
Q
A

center aligned

22
Q

fill character

A

you can pad with a specific character, like 0s

23
Q

{score:0>4}

A

pad with zeros, right aligned, field width of 4

24
Q

percision

A

number of places after the decimal point (rounds)

25
Q

{1.725:.1f}

A

1.7

26
Q

replace(old, new)

A

returns copy of string with all occurances of old replaced with new

27
Q

replace(old, new, count)

A

returns copy of string with first COUNT occurances of old replaced with new

28
Q

find(x)

A

returns index of first occurance of x

29
Q

find(x, start)

A

returns index of first occurance of x from index start onwards

30
Q

find(x, start, end)

A

returns index of first occurance of x between start and end index

31
Q

rfind(x)

A

returns index of first occurance backwards( searches string in reverse)

32
Q

count(x)

A

counts number of occurances of X

33
Q

string comparisons

A

compares ASCII number of 1st elements, if everything is the same the shorter string is less than the alrger

34
Q

is/is not

A

compares object types, not values

35
Q

isalnum()

A

true if chars are letter or number

36
Q

isdigit()

A

true if chars are numbers

37
Q

startswith(x)

A

true if string starts with x

38
Q

endswith(x)

A

true if string ends with x

39
Q

capitalize()

A

capitalizes first character of string

40
Q

strip()

A

removes all whitespace at start and end of string

41
Q

title()

A

makes starting title with each word capitalized

42
Q

split()

A

split string into list of tokens

43
Q

token

A

substring that forms part of a larger string

44
Q

separator

A

character or sequence that indicates where string splits into tokens, if there’s a double separator then that list item is empty quotes

45
Q

join method

A

inverse of split, joins list of strings based on delimeter

46
Q

’‘.join(x)

A

x is the list and the delimeter to join is ‘’