WorksheetsData Analytics Quiz-2
Total questions: 10
Worksheet time: 5mins
What is the output of the following code?
```python
string = "Hello, world!"
print(string[7:12])
```
world
, wor
world!
Hello
Which of the following strings is correctly enclosed using single quotes?
"This is a string"
'Another string'
`Yet another string`
'''String with triple single quotes'''
What is the length of the string "GPT-3.5 is amazing."?
13
15
17
18
Which string method can be used to convert a string to uppercase letters?
upper()
capitalize()
title()
casefold()
What is the index of the first occurrence of the letter 'o' in the string "Coding is fun and challenging."?
4
6
8
10
Which of the following data structures in Python stores data in key-value pairs?
List
Tuple
Set
Dictionary
How are dictionary keys accessed in Python?
A)
B)
C)
D)
Using indexes
Using parentheses
Using curly braces
Using square brackets
What happens if you try to add a key that already exists in a dictionary?
An error is raised
The existing value for that key is replaced
The dictionary remains unchanged
The dictionary automatically resizes
Which method is used to remove a key-value pair from a dictionary in Python?
popitem()
remove()
delete()
pop()
What is the result of the following code snippet?
```python
student = {
"name": "Alice",
"age": 20,
"grade": "A"
}
student["school"] = "XYZ School"
print(len(student))
```
3
4
5
6
