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 :: onehot encode list of columns pandas 
Python :: pandas filter 
Python :: longest palindromic substring using dp 
Python :: clear 
Python :: how to sort numpy array 
Python :: remove all occurences 
Python :: how to schedule python script in windows 
Python :: python pandas how to access a column 
Python :: Example of floor method in python 
Python :: replace nan from another column 
Python :: daraja mpesa 
Python :: iterating string in python 
Python :: select multi columns pandas 
Python :: pandas how to read csv 
Python :: how to use djoser signals 
Python :: pandas drop columns 
Python :: variables in python 
Python :: input() function in python 
Python :: python singleton module 
Python :: format datetime python pandas 
Python :: args in python 
Python :: python eval 
Python :: python 3.8 release date 
Python :: github downloader 
Python :: how to remove item from list in python 
Python :: python move files 
Python :: python a, b = 
Python :: commands.has_role discord.py 
Python :: asyncioevents.py", line 504, in add_reader raise NotImplementedError 
Python :: import numpy as np import matplotlib.pyplot as plt index = 0 missClassifiedIndexes = [] for label, predit in zip(y_test, predictions): if label != predict: missClassifiedIndexes.append(index) index = +1 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =