Question : W3Schools Var-coll-F 26

1. List Append Understanding

What will be the output?

colors = []
colors.append("red")
colors.append("blue")
print(colors)
2. Extend vs Append

Explain the difference between:

list1.append(['a','b'])
list1.extend(['a','b'])
3. Removing Elements

What does this code print?

a = ["x","y","z","w"]
a.pop(1)
print(a)
4. Pop With No Index

Why does list.pop() remove the last item, even when no index is provided?

5. Insert in List

What will be printed?

nums = [10, 20, 30]
nums.insert(1, 15)
print(nums)
6. Replacing List Items

Write code to replace the third element of a list with "DONE".

7. Tuple Immutability

Why does the following cause an error?

t = (3,4,5)
t[1] = 7
8. Dictionary Duplicate Keys

Explain what the final value of 'Pen' will be here:

car = {'Pen': 10, 'Pen': 5000, 'Pen': 1}
9. Accessing Dictionary Value

What does this print?

car = {"brand": "Toyota", "year": 2020}
print(car["brand"])
10. Add New Key to Dict

Write code to add "color": "Black" to an existing dictionary.

11. Set Duplicate Removal

Explain why this prints fewer numbers than listed:

s = {1,1,2,2,3,3}
print(s)
12. Convert List to Set

What is the purpose of converting this list to a set?

names = ["a","b","a","a","c"]
unique = set(names)
13. Input + List

Write code that asks the user for 3 colors and stores them in a list.

14. Input + Condition

Write code that asks the user for a number.
If the number is more than 10, print "High", else print "Low".

15. Input + Dictionary

Write code that asks the user for a name and age, and saves them in a dictionary.

16. Condition on List Length

What does the following print if the list has more than 5 items?

items = [1,2,3,4,5,6]
if len(items) > 5:
    print("Long list")
else:
    print("Short list")
17. Checking if Item Exists

Write code to check if "blue" is in the list colors.
If yes, print "found".

18. Input + Set

Ask the user to enter 5 names, store them in a set, and print how many UNIQUE names were entered.

19. Dictionary Condition

Given:

student = {"name": "John", "score": 45}

Write a condition to print "Pass" if score ≥ 50 else "Fail".

20. List Pop Based on Input

Ask the user for an index number.
Remove the item at that index from a list using .pop(index).

 

Write what you are looking for, and press enter to begin your search!