List Extend in Python
Level 248 keystrokes
This extends a list by adding elements from another list. The extend() method modifies the original list.
Python code
# Create a list with three numbers1nums = [1, 2, 3]# extend() appends each element of [4, 5] to the end of nums# Unlike append([4, 5]), it does not add the list as one nested element2nums.extend([4, 5])# Prints the modified list: [1, 2, 3, 4, 5]3print(nums)Output
[1, 2, 3, 4, 5]
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this Python code and how often they appear.
,× 3(× 2)× 2[× 2]× 2.× 1=× 1