Match the following code snippets to the type of literal that they define.
x = (1,2,3)
x = [1,2,3]
x = {1,2,3}
x = {'a': 1, 'b': 2, 'c': 3}
x = "hello world" - Answers tuple
list
set
dictionary
string
Consider the following statement that declares a tuple:
t = ("Hello", "world", "!")
How do you retrieve the second element from the tuple?
- second = t.item0
- second = t.get(2)
- second = t[2]
- second = t[1] - Answers second = t[1]
Given the following dictionary declaration:
d = { "first": "Hello", "second": "world", "third": "!" }
How do you access the first element in the dictionary. Select all that apply.
- d = d["first"]
- first = d.get("first")
, - first = d.get("first", "Hello")
- d = d.item0 - Answers - d = d["first"]
- first = d.get("first")
- first = d.get("first", "Hello")
Given the following class definition and statement:
class Greeting():
first = "Hello"
second = "world"
third = "!"
g = Greeting()
How do you access the named attribute third?
- third = g.get("third")
- third = g["third"]
- third = g.third
- third = g[3] - Answers third = g.third
When using an expression to determine truthiness, False will be returned for:
- The literal value False
- Zero
- None
- Empty strings, lists, tuples, and dictionaries
- All of the above
- None of the above - Answers All of the above
When using an expression to determine truthiness, which conditions will True be returned for?
- The literal value True