Basic Rehash Flashcards

Identify places in Python Fundamentals that need more work.

1
Q

Name 3 components of a print() statement

A

String, value, end argument

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

Identify two ways to print an entire list

A

print(list) or print(list[:])

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

Identify list index components

A

list[position:range:steps]

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

Name all list methods

A

append()
insert()
extend()
del
remove()
pop()
reverse()

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

list.append(object)

A

Adds an object to the end of a list.

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

list.insert(position, value)

A

Adds a value to the position identified in a list specified.

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

list.extend(object)

A

Adds the value(s) inside of an object to a list

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

del list[position]

A

Deletes the value at a particular position. This acts as an operator in this example, not a method.

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

list.remove(value)

A

Removes a value within the list without specifying a location.

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

list.pop()

A

Removes the last element of a list.

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

What happens if you add an argument to the pop() method?

A

It will treat it as a position and remove that value from that position.

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

list.reverse()

A

Displays a list from right to left without changing the actual positioning of the list variable.

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

Identify the layout of an “inclusion” if statment

A

if value in list:

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

What should you add to an end of a While loop?

A

An else statement.

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

Go over the funny inclusive/exclusive property of an index range.

A

When you select a range from a list index, such as var[0:3], the number on the left of the ‘:’ is inclusive, meaning it is included in the range, but the value on the right of the ‘:’ is exclusive, meaning it is NOT included in the requested range. So, in a list of 1, 2, 3, 4, the index request of var[0:3] would be: 1, 2, 3

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

Tuples are…

A

immutable, meaning the value cannot be altered

17
Q

How do you get a list of all keys in a dictionary?

A

dictionary_var.keys()
outputs: dict_keys([…

18
Q

How do you get a list of all values in a dictionary?

A

dictionary_var.values()
outputs: dict_values([…

19
Q

What tells the print() function to print on the next line?

A

‘\n’ in the same string.

20
Q

range()

A

Often used in loops to generate a sequence of numbers.
Versatile tool in creating iterable stop, start, and step values.

21
Q

How do you pop from a dictionary?

A

Identify the key you want to remove from the dictionary. Since the dictionary is unordered, a blank .pop() will return an error.

22
Q

Type Casting

A

The process of converting one data type to another.
Commonly used when working with data in loops to ensure compatibility and perform specific operations.

23
Q

What’s the benefit of using range()

A

Allows to loop through a large amount of data without consuming a lot of memory.

24
Q

Format a list comprehension for applying a 5% discount to a list of prices in a price_list list variable.

A

discounted_price_list = [x-(x*(5/100)) for x in price_list)

25
Q

Format a list that will return each value of the list as yes or no according to comparisons on a budget value to other items in the discounted_price_list list variable.

A

budget_list = [‘Yes’ if x <= budget else ‘No’ for x in discouted_price_list]

26
Q

What is the typical syntax of a function?

A

def function_name(parameters):
‘'’explain what the function does’’’
statement(s)

27
Q

What parameter controls the space between parameter values output by the print() function?

28
Q

return statement

A

A function that returns a value.

29
Q

lambda function

A

A very short function that is done in a single line (inline function) to make the code more Pythonic.
lambda keyword does need to be called:
function_name = lambda parameter(s),.. : statement

30
Q

What is the purpose of a lambda function?

A

Creates anonymous, small, and simple functions.

31
Q

What value will display when you run this code:
mul = lambda a,b: return a*b
mul(5,6)

A

It will return an error, specifically:
SyntaxError: invalid syntax

32
Q

What is the order of Positional arguments to Keyword arguments in a function?

A

positional before keyword

33
Q

Keyword arguments are stored in a…

A

dictionary

34
Q

How do you identify a Keyword argument in a function call?

A

Put a ** in front of the parameter passed to the function. i.e.
function_name(**kwargs)