Skip to content

Instantly share code, notes, and snippets.

@Robofied
Created February 5, 2019 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robofied/ac5eb05b75b164af52562f0c8889f55e to your computer and use it in GitHub Desktop.
Save Robofied/ac5eb05b75b164af52562f0c8889f55e to your computer and use it in GitHub Desktop.
## 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