Latest Update | Graded A+
1. Describe how the `.join()` method can be used with a list of strings.
The `.join()` method splits a string into a list based on a delimiter.
The `.join()` method can be used to combine a list of strings into
one string, separated by a specified delimiter.
The `.join()` method converts a list of strings into a dictionary.
The `.join()` method formats strings by adding prefixes and suffixes.
2. What characteristic of a list in Python allows it to hold multiple instances of
the same value?
It is unordered.
It can contain duplicate elements.
It is immutable.
It can only hold unique items.
3. If a function defines a local variable and then calls another function that tries
to access that local variable, what will happen?
The local variable will be passed to the second function as an
argument.
The second function will successfully access the local variable.
The second function will raise an error because it cannot access the
local variable.
The local variable will become a global variable.
4. Where are global variables defined in Python?
, Outside of any function
In a separate module
Inside a function
Within a class
5. What is the escape sequence for a backslash character?
\
\\
//
/
6. Describe the purpose of string manipulation methods in Python and provide
an example.
String manipulation methods in Python are used to format strings. For
example, 'Hello, {}'.format('world') returns 'Hello, world'.
String manipulation methods in Python are used to concatenate
strings. For example, 'hello' + ' world' returns 'hello world'.
String manipulation methods in Python are used to split strings into
lists. For example, 'a,b,c'.split(',') returns ['a', 'b', 'c'].
String manipulation methods in Python are used to modify strings,
such as changing their case or replacing characters. For example,
'world'.replace('w', 'W') returns 'World'.
7. Describe the process of unpacking collections in Python and provide an
example.
Unpacking collections refers to defining functions that can return
multiple values.
, Unpacking collections combines multiple variables into a single list or
tuple.
Unpacking collections is the process of converting a string into a list
of characters.
Unpacking collections involves taking elements from a list or tuple
and assigning them to separate variables, such as 'a, b = [1, 2]'.
8. Describe the process of unpacking a list in Python and its significance.
Unpacking a list in Python involves assigning each element of the
list to a separate variable, allowing for easier access to individual
elements.
Unpacking a list in Python requires the use of a loop to iterate through
the list elements.
Unpacking a list in Python combines all elements into a single variable
for easier manipulation.
Unpacking a list in Python is only possible with tuples, not lists.
9. The meaning of a positional argument is determined by:
its connection with existing variables
the argument's name specified along with its value
its value
its position within the argument list
10. If a function needs to modify a global variable, what must be included in the
function definition to ensure the modification is successful?
The global keyword
The local keyword
, The static keyword
No special keyword is needed
11. What syntax is used to create an f-string in Python?
'Hello {name}'
'Hello name'
f'Hello {name}'
f'Hello name'
12. Which of these lines of code will generate a random number between 1 and
50?
num = random.randint(1,50)
input("1-50")
import random
print("1-50")
13. What keyword is used in Python to declare a global variable within a
function?
global
local
static
constant
14. What is the purpose of the str.capitalize() method in Python?
Reverse the order of characters in the string