author | Anoop Jacob Thomas<anoop@fossee.in> |
Tue, 12 Oct 2010 13:02:39 +0530 | |
changeset 306 | f105cfcc2498 |
parent 232 | da873a5ac918 |
child 425 | c943cdbee397 |
permissions | -rw-r--r-- |
232
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
1 |
Objective Questions |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
2 |
------------------- |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
3 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
4 |
1. Define a tuple containing two values. The first being integer 4 and second |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
5 |
is a float 2.5 |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
6 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
7 |
Answer: (4, 2.5) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
8 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
9 |
2. If ``a = (5, "Hello", 3.2)``. what is the value of a[2] |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
10 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
11 |
Answer: 3.2 |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
12 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
13 |
3. If ``a = 5,`` then what is the type of a |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
14 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
15 |
a. int |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
16 |
#. float |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
17 |
#. tuple |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
18 |
#. string |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
19 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
20 |
Answer: tuple |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
21 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
22 |
4. if ``a = (2, 3)``. What does ``a[0], a[1] = (3, 4)`` produce |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
23 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
24 |
Answer: Error |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
25 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
26 |
5. If ``a = ([2, 3], 4, 5)``. What is the value of ``a`` after doing |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
27 |
``a[0].append(6)`` |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
28 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
29 |
a. ([2, 3, 6], 4, 5) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
30 |
#. Raises an error |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
31 |
#. ([2, 3], 4, 5) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
32 |
#. [2, 3, 4, 5, 6] |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
33 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
34 |
Answer: ([2, 3, 6], 4, 5) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
35 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
36 |
6. What does the following code produce:: |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
37 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
38 |
a = 5 |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
39 |
b = "Hello" |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
40 |
a, b = b, a |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
41 |
print a |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
42 |
print b |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
43 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
44 |
Answer:: |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
45 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
46 |
Hello |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
47 |
5 |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
48 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
49 |
7. ``a = ("hello", "world", 5, 6, 8)``. What is the value of a[1:4] |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
50 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
51 |
Answer: ("world", 5, 6) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
52 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
53 |
8. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[1::3] |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
54 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
55 |
Answer: (2, 5, 8) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
56 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
57 |
9. ``a = (1, 2, 3, 4, 5, 6, 7, 8)``. What is the value of a[-3::-1] |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
58 |
|
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
59 |
Answer: (6, 5, 4, 3, 2, 1) |
da873a5ac918
made the tuples.rst into new template form
Nishanth <nishanth@fossee.in>
parents:
diff
changeset
|
60 |