Created
February 5, 2019 07:13
-
-
Save Robofied/ac5eb05b75b164af52562f0c8889f55e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Append() method | |
## It added one more new element '7' in the last. | |
l4.append(7) | |
print(l4) | |
#[Output]: | |
[1, 2, 3, 2, 3, 4, 5, 6, 7] | |
## We can also add sublist as an element in the original list as we saw earlier, list is ## heterogenpus in nature. | |
l4.append([1,2]) | |
print(l4) | |
#[Output]: | |
[1, 2, 3, 2, 3, 4, 5, 6, 7, [1, 2]] | |
l4.insert(5,1) | |
## See it shifted elemnts from index 5 to right and inserted 1 at index 5. | |
print(l4) | |
#[Output]: | |
[1, 2, 3, 2, 3, 1, 4, 5, 6, 7, [1, 2]] | |
## extend() method | |
## Here we appended the elements present in the l3 to l4. | |
l4.extend(l3) | |
print(l4) | |
#[Output]: | |
#[1, 2, 3, 2, 3, 1, 4, 5, 6, 7, [1, 2], 'a', 1, 'hello'] | |
## It will remain the same. | |
print(l3) | |
#[Output]: | |
['a', 1, 'hello'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment