author | Amit Sethi |
Tue, 09 Nov 2010 15:15:19 +0530 | |
changeset 417 | fc71d5c27ce6 |
parent 374 | 57d145c18ccd |
permissions | -rw-r--r-- |
225
94bcf44b05ad
Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
1 |
Objective Questions |
94bcf44b05ad
Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
2 |
------------------- |
213 | 3 |
|
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
4 |
.. A mininum of 8 questions here (along with answers) |
213 | 5 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
6 |
1. How do you create an empty list? :: |
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
7 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
8 |
empty=[] |
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
9 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
10 |
2. What is the most important property of sequence data types like lists? |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
11 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
12 |
The elements are in order and can be accessed by index numbers. |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
13 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
14 |
3. Can you have a list inside a list ? |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
15 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
16 |
Yes,List can contain all the other data types, including list. |
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
17 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
18 |
Example: |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
19 |
list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there'] |
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
20 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
21 |
4. What is the index number of the first element in a list? |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
22 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
23 |
0 |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
24 |
nonempty = ['spam', 'eggs', 100, 1.234] |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
25 |
nonempty[0] |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
26 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
27 |
5. How would you access the end of a list without finding its length? |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
28 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
29 |
Using negative indices. We can the list from the end using negative indices. |
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
30 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
31 |
:: |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
32 |
nonempty = ['spam', 'eggs', 100, 1.234] |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
33 |
nonempty[-1] |
213 | 34 |
|
320
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
35 |
6. What is the function to find the length of a list? |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
36 |
|
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
37 |
len |
223044cf254f
Adding new format st-scripts with questions etc for basic-data-type and
amit
parents:
225
diff
changeset
|
38 |
|
374 | 39 |
7. Delete the last element from list sq=[5,4,3,2,1,0] |
40 |
||
41 |
del(sq[-1]) |
|
42 |
||
43 |
8. How many will you have to use remove function to remove all 6's from the given list sq=[2,5,6,7,6,4,6]? |
|
44 |
||
45 |
3 |
|
213 | 46 |
|
225
94bcf44b05ad
Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
47 |
Larger Questions |
94bcf44b05ad
Minor changes to questions.rst template.
Puneeth Chaganti <punchagan@fossee.in>
parents:
223
diff
changeset
|
48 |
---------------- |
213 | 49 |
|
223
ce0e8c99eaee
Added answer format to questions.rst.
Puneeth Chaganti <punchagan@fossee.in>
parents:
216
diff
changeset
|
50 |
.. A minimum of 2 questions here (along with answers) |
213 | 51 |
|
342 | 52 |
1. Add all elemets of seq1=['e','f','g','h'] |
53 |
to the sequence seq=['a','b','c','d'] |
|
54 |
||
55 |
2. Delete all elements of seq1=[3,5,6] from sequence |
|
56 |
seq=[1,2,3,4,5,6,7,8,9] |