Computer Science
In the Python shell, do the following :
- Define a variable named states that is an empty list.
- Add 'Delhi' to the list.
- Now add 'Punjab' to the end of the list.
- Define a variable states2 that is initialized with 'Rajasthan', 'Gujarat', and 'Kerala'.
- Add 'Odisha' to the beginning of the list states2.
- Add 'Tripura' so that it is the third state in the list states2.
- Add 'Haryana' to the list states2 so that it appears before 'Gujarat'. Do this as if you DO NOT KNOW where 'Gujarat' is in the list. Hint. See what states2.index("Rajasthan") does. What can you conclude about what listname.index(item) does ?
- Remove the 5th state from the list states2 and print that state's name.
Related Questions
What are the two ways to remove something from a list? How are they different ?
What is the difference between a list and a tuple ?
Discuss the utility and significance of tuples, briefly.
If a is (1, 2, 3)
- what is the difference (if any) between a * 3 and (a, a, a) ?
- Is a * 3 equivalent to a + a + a ?
- what is the meaning of a[1:1] ?
- what is the difference between a[1:2] and a[1:1] ?