Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

extend python

# Extend Method on Lists 
# The extend() method adds a list variable to another list 
# specified as an argument when you run the list's method.

# We have a list of random names here:
random_names = ["Isabella", "Laura", "Robert", "Andrew", "Bob", "Angela"]

# Print the current list to the terminal so that we can view the before and
# after afterwards.

print(random_names)

"""
The extend method is a method because a list is an object/class created 
behind the scenes. To utilize it, you must type the list variable name,
then a dot, followed by the word "extend" with parentheses afterwards.
Then inside those parentheses, make a tiny list. Let's say there is Bob's
friend, Stanley. And Stanley's other friend is Tristan. Let's add those
name strings to the list! So the syntax is:
"""

random_names.extend(["Stanley", "Tristan"])

"""Under the hood, how this is working is basically the list we defined as
an argument down below will be added to the list we put before the dot like
this:

random_names = random_names + ["Stanley", "Tristan"]
"""

# Lastly, we print the list to see the new changes

print(random_names)

Comment

.extend python

Color = ["Blue", "Pink", "Yellow", "Green"]
Number = (2, 4, 12, 20)
Color.extend(Number)
print(Color)

#output
#['Blue', 'Pink', 'Yellow', 'Green', 2, 4, 12, 20]
Comment

what is the use of extend in python

The extend() method adds the specified list elements (or any iterable) to the end of the current list.
Comment

PREVIOUS NEXT
Code Example
Python :: instance of object 
Python :: Python program to find second largest 
Python :: turn numpy function into tensorflow 
Python :: python transpose 
Python :: Python NumPy concatenate Function Syntax 
Python :: pop element from list python 
Python :: bayesian model probability 
Python :: python use cases 
Python :: pandas drop rows 
Python :: how to make a variable in python 
Python :: hash table python 
Python :: python iterrows 
Python :: groupby as_index=false 
Python :: search object in array python 
Python :: Tree recursive function 
Python :: spread in python 
Python :: python program to find sum of array elements 
Python :: zipfile python unzip with path 
Python :: How to append variable in Python 
Python :: python string: built-in function len() 
Python :: something useless. python 
Python :: select columns rsnge dataframe 
Python :: function palindrome python 
Python :: image segmentation pyimagesearch 
Python :: extract parameter of voice using python 
Python :: one line test python 
Python :: channel unlock command in discord.py 
Python :: module django contrib admin has no attribute action ACTION_CHECKBOX_NAME 
Python :: pandas split coordinate tuple 
Python :: hmac decrypt python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =