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
fill character
you can pad with a specific character, like 0s
23
{score:0>4}
pad with zeros, right aligned, field width of 4
24
percision
number of places after the decimal point (rounds)
25
{1.725:.1f}
1.7
26
replace(old, new)
returns copy of string with all occurances of old replaced with new
27
replace(old, new, count)
returns copy of string with first COUNT occurances of old replaced with new
28
find(x)
returns index of first occurance of x
29
find(x, start)
returns index of first occurance of x from index start onwards
30
find(x, start, end)
returns index of first occurance of x between start and end index
31
rfind(x)
returns index of first occurance backwards( searches string in reverse)
32
count(x)
counts number of occurances of X
33
string comparisons
compares ASCII number of 1st elements, if everything is the same the shorter string is less than the alrger
34
is/is not
compares object types, not values
35
isalnum()
true if chars are letter or number
36
isdigit()
true if chars are numbers
37
startswith(x)
true if string starts with x
38
endswith(x)
true if string ends with x
39
capitalize()
capitalizes first character of string
40
strip()
removes all whitespace at start and end of string
41
title()
makes starting title with each word capitalized
42
split()
split string into list of tokens
43
token
substring that forms part of a larger string
44
separator
character or sequence that indicates where string splits into tokens, if there's a double separator then that list item is empty quotes
45
join method
inverse of split, joins list of strings based on delimeter
46
''.join(x)
x is the list and the delimeter to join is ''