Python Revision tour - 2 || Type A || Sumita Arora || Class 12 || Computer science || Information practices || Solution || 



Q 1 = What is the internal structure of Python strings ?


Q 2 = Write a Python script that traverses through an input string and prints its characters in different lines- two characters per line. 

 

Q 3 = Discuss the utility and significance of Lists, briefly. 

 

Q 4 = What do you understand by mutability ? What does "in place" task mean ? 

 

Q 5 = Start with the list [3, 9, 10]. Do the following :

(a) Set the second entry (index 1) to 17

(b) Add 4, 5 and 6 to the end of the list

(c) Remove the first entry from the list

(d) Sort the list

(e) Double the list

(f) Insert 25 at index 3

 

Q 6 = What's a [1: 1] if a is a string of at least two characters ? And what if string is shorter ?



Q 8 = What are the two ways to remove something from a list? How are they different ?



Q 10 = In the Python shell, do the following :

(i) Define a variable named states that is an empty list.

(ii) Add 'Delhi' to the list.

(ii) Now add 'Punjab' to the end of the list.

(iv) Define a variable states2 that is initialized with 'Rajasthan', 'Gujrať, and 'Kerala'.

(v) Add 'Odisha' to the beginning of the list.

(vi) Add ‘Tripura’ so that it is the third state in the list. (vii) Add 'Haryana' to the list so that it appears before 'GujraÅ¥. Do this as if you DO NOT KNOW where 'GujraÅ¥ is in the list.

(viii) Remove the 5th state from the list and print that state's name. 

 

Q 11 = Discuss the utility and significance of Tuples, briefly. 

 

Q 12 = If a is (1, 2, 3)

(a) what is the difference (if any) between a * 3 and (a, a, a)?

(b) is a * 3 equivalent to a + a + a ?

(c) what is the meaning of a[1:1] ?

(d) what's the difference between a[1:2] and a[1:1] ? 

 

Q 13 = What is the difference between (30) and (30,) ?


Q 14 = Why is a dictionary termed as an unordered collection of objects ?


Q 15 = What type of objects can be used as keys in dictionaries ? 


Q 16 = Though tuples are immutable type, yet they cannot always be used as keys in a dictionary. What is the condition to use tuples as a key in a dictionary ? 

Q 17 = Dictionary is a mutable type, which means you can modify its contents ? What all is modifiable in a dictionary ? Can you modify the keys of a dictionary ?


Q 18 = How is del D and del DI<key>] different from one another if D is a dictionary ?


19. Create a dictionary named D with three entries, for keys 'a' ‘b’ and ‘c’. What happens if you try to index a nonexistent key (D['d']) ? What does Python do if you try to assign to a nonexistent key a (e.g., D['d']='spam') ? 

 

Q 20 = What is sorting ? Name some popular sorting techniques. 

11 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. THANK U....

    ReplyDelete
  2. 2nd answer is wrong
    it would be
    a = input("Enter a string = ")
    for i in range (2 , len(a)+2 , 2 ) :
    print( a [ i - 2 : i])

    or

    a = input("Enter a string = ")
    for i in range (0 , len(a), 2 ) :
    print( a [ i : i+2])

    ReplyDelete
    Replies
    1. Our program is right. Please run that answer in IDLE Python.

      Delete
  3. Question 5(b), it should be l.extend([4,5,6])

    ReplyDelete
  4. Thabk you and may the force be with you

    ReplyDelete
  5. update the question

    ReplyDelete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post