Week 2-FAQs
Week 2-FAQs
General- FAQs
1. In a list the sub level component index starts from 0 and the inner level elements
start from 0 or 1…?
Ans. In python indexing starts from 0 to n-1. For sub level as well it starts from 0
3. When List_1 is concatenated with List_2 , does the length of the List_1 change?
Ans. The length of the List_1 will not change unless you update it in the existing list. If
we assign it to a new variable length of the list changes depending on the number of
elements.
6. How does one change the name of the key once assigned?.
Ans. Keys cannot be changed. You need to add a new key with the modified value then
remove the old one, or create a new dictionary with a new dictionary key.
8. I f an element occurs twice or thrice, does remove method remove all occurrences or
only the first occurrence?
Ans. remove method removes only the first occurrence of the value.
12. hat if more than 2 words are repeated and we want to remove the word more
W
than 2 so how can we use the remove()?
Ans. Kindly write a loop and execute the statements.
14. hen I created a dictionary, The order in which I am creating and the order in
W
which it prints is different.
Ans. Dictionary will have key value pairs and stored in an unordered manner.
15. What makes tuples different from lists?
Ans. In lists you can add, modify and delete the elements.
Once tuple is created you will not be able to modify the elements.
19. We print the combine tuple directly then it'll do any changes in the database ?I
mean it will store the data forever or just will store on a temporary basis?
Ans.Combined tuple will be printed but it will not be updated.
You can store the combined tuple in variable for future purpose.
21. How to use insert() in case of negative indexing? Does insert() function have positive
indexing as default?.
Ans.Instead of positive indexing you can also specify the negative indexing value.
22. When we use a pop method whether it will print the pop element or not.
Ans. The pop() method removes the item at the given index and returns the removed
item.
23. What is meant by String in python?
Ans. A string is a sequence of one or more characters (letters, numbers, symbols) that can
be either a constant or a variable. Made up of Unicode, strings are immutable sequences
Numpy
2. To add a new array to an existing array ,I have used the below code
np.append(a,[[10,11,14]],axis=0)
But it added in the end ,why?
Ans. It is due to the append f unction.
append a dds the value at the end of the array.
3. How do we know whether it is positive indexing or negative indexing ? Is there any
command to know about indexing?
Ans. The positive index starts from 0 to n-1 (with positive sign)
Negative indexing is used to access elements from the end of a list
negative indexing starts from -1 to -(n) (with negative sign)
4. What does ":" mean while accessing the subset of the array?
Ans. The : operator slices a part from a sequence object such as list, tuple or string. It
takes two arguments. First is the index of the start of slice and second is index of end
of slice. Both operands are optional. If the first operand is omitted, it is 0 by default.
If the second is omitted, it is set to the end of the sequence.
Example:
a=[1,2,3,4,5,6,7]
a[1:3]
[2, 3]
del() - The del keyword is used to delete objects. You can pass the variable name with
the index value inside the braces.