Strings
Functions
Lists/Tuples
Methods
Random
100

What are the three types of whitespace you can have inside a string? 

" " (space), "\t" (Tab), "\n" (Newline)

100

Name one of the functions we have been using for a while now and describe what it's job is.

Options: print(), input(), len(), int(), float(), bool(), str()

100
What is one approach I can use to loop through the items in a list?

Options: 

for loop, while loop for indexing, list comprehension

100

What will the string method .split(",") return if applied to any string?

A list of strings that have been split whenever there is a comma character. 

100
Can I include a list as an item inside another list? If so, how does that affect indexing?

Yes. You would have to index multiple times until you get to the item.

200

Name one string operation (there are 3 we learned about) and describe what it does.

1. + - concatenates strings

2. * - repeats strings 

3. in - check if certain character or pattern of characters is in our string

200

What are the 3 general steps we said could be applied to any function?

1. Takes 0 or more inputs as parameters

2. Does some operation(s) a.k.a it's specific job

3. Returns an output object (optional)

200
How do I create a list and how do I create a tuple?

list = [x, y, z]

tuple = (x, y, z)

200

What data type will the method .isalpha() return? Why is this the case?

Bool type because it is checking if the string is either all letters from the alphabet or not, and that can either be True or False, nothing else. 

200

Of the following data types, which ones are immutable?

int, float, lists, tuples, str, bool

int, float, tuples, str, bool

300

What do the three arguments represent when slicing a string using the following syntax: my_string[x:y:z]

my_string[start_index:end_index:stride]

300

How many arguments/parameters can I have in a function definition? How do I include these in my function definition?

As many as I want. Separate them with  commas

300

What is the main difference between lists and tuples?

lists - mutable

tuples - immutable lists

300

Name two string methods that we learned about and give an example of how we can use them.

Options: 

.upper(), .lower(), .isalpha(), .isdigit(), .replace(), ...etc.

300

What would the following line of code produce?

print(1 + 2 + 3 + "4")

Type Error! 

400

How do string comparisons work? Explain in detail.

Every pair of characters in both strings are compared. If the comparison holds True for that pair, we compare the next pair and so on until the comparison is False or we reach the end of the strings.


400

What will happen if I run the following code:

def mystery_function(num):

    if num > 0:

        return num * 3

    else:

        return -1

mystery_function()

 Error!

I am not including the parameter that my definition says I need. How can I fix this?

400

What would the following code output?

print( ([1, 2, 3] + [4, 5, 6]) * 2)

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

400
Name two list methods that we learned about and give an example of how we can use them.

Options: 

.append(), .pop(), .remove(), .insert(), .sort(), .index(), .count()

400

What is the difference between methods and functions? How do I call each one?

Methods are a specials types of functions that are targeted towards a specific data type. Methods use dot notation and Functions use function notation. 

my_string.method_name()

function_name(my_string)

500

What would the following line of code return?

"lunabear     ".strip().upper().replace("L", "B").replace("L", "T")

"BUNABEAR"

500

When and why do I need to use the return keyword in my function definition? Is there every a scenario in which I don't need to return information?

When you want to return information from inside the function back outside the function (remember we don't know what the elf is doing). UNLESS, we are editing a mutable data type (ex: lists). Then, we don't need to return because our the elf's edits are updated automatically.

500

What is the difference between my_list.remove(2) and my_list.pop(2)

my_list.pop(2) will remove and return the element at index 2 of my_list. 


my_list.remove(2) will remove the first instance from left to right of the element of value 2 in my_list.

500

What is the difference between my_list.sort() and sorted(my_list)?

.sort() - modifies the list itself

sort() - modifies a copy of the list and returns the copy (the original stays untouched)

500

what can we use the key parameter for in sorted() and .sort(). Give an example.

The key parameter specifies a function to be applied to each element prior to being compared. Examples: str.lower, str.upper, str.capitalize