Worked Examples · Example 5.4
Q.Example 5.4:
#To create a list
list1 = [5, 3.4, "New Delhi", "20C", 45]
#print the elements of the list list1
print(list1)
[5, 3.4, 'New Delhi', '20C', 45]
list1 = [5, 3.4, "New Delhi", "20C", 45]
#print the elements of the list list1
print(list1)
[5, 3.4, 'New Delhi', '20C', 45]
Uttarakhand UbseTextbookSubjective· 2mImportance★★★★★est
14% · 7/49 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →A list is an ordered, mutable collection written in square brackets that can mix types — print(list1) echoes the whole list, showing strings in single quotes.
The concept is the list data type: Python's workhorse sequence. Three properties matter — a list is ordered (elements keep their positions, indexed from 0), mutable (elements can be changed later), and heterogeneous (it can hold values of different types together).
#To create a list
>>> list1 = [5, 3.4, "New Delhi", "20C", 45]
#print the elements of the list list1
>>> print(list1)
[5, 3.4, 'New Delhi', '20C', 45]
What is inside list1, position by position:
| Index | Element | Type |
|---|---|---|
| 0 | 5 | int |
| 1 | 3.4 | float |
| 2 | 'New Delhi' | str |
| 3 | '20C' | str |
| 4 | 45 | int |
Two observations about the printed output:
- The elements come back in exactly the order they were entered — lists preserve order.
- The strings were typed with double quotes but print back in single quotes ('New Delhi'). Python's canonical representation of a string uses single quotes; both quote styles create identical str objects. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.