DigitalOcean Referral Badge
Udit Vashisht
Author: Udit Vashisht


How to append to a list in Python ? - Python List append() method

  • Less than a minute read
  • 238 Views
How to append to a list in Python ? - Python List append() method

    Table of Contents

Python List append() method

The Python list append() method adds an item to the end of the list. The length of the list increase by one.

Syntax of append()

The syntax for the same is :-

list_name.append(item)

Parameters of append()

The method takes only a single argument

item - an item to be added at the end of the list

The item can be any object like number, string, dictionary, list, set, boolean, etc.

Return value of append()

The append() method doesn’t return anything and just changes the list inplace. Hence, it returns None.

Example of appending an element to a list

color_list = ['red', 'yellow', 'blue']
color_list.append('green')

print(color_list)
['red', 'yellow', 'blue', 'green']

Example of appending a list to a list

color_list.append(['black', 'white'])

print(color_list)
['red', 'yellow', 'blue', 'green', ['black', 'white']]

Related Posts

Chapter 3 - Executing a Python Script
By Udit Vashisht

How to run a Python script?

In our previous chapter, we have strongly recommended you to ditch IDLE and use some code-editor and terminal(MacOS/Linux) or Powershell(Windows) to write and execute your python script. In this chapter we will tell you how to do that.

First and foremost for the ...

Read More
Chapter 7- Numbers, Conversions and Operators
By Udit Vashisht

In the previous chapter, we learned about various datatypes. From this chapter onward, we will learn in detail about each data type.

Numbers in Python

This datatype stores the numeric values and is immutable. For the beginners, it is sufficient to understand that immutable objects are those which can ...

Read More
How to host and schedule your python script on PythonAnywhere?
By Udit Vashisht

In our last post here, we learned how to create a python script which will automatically delete your messages from gmail account based on a query.

The complete ready-to-use code can be found here.

Follow the steps in the above tutorial to download the ‘credentials.json’ file and ...

Read More
Search
Tags
tech tutorials automate python beautifulsoup web scrapping webscrapping bs4 Strip Python3 programming Pythonanywhere free Online Hosting hindi til github today i learned Windows Installations Installation Learn Python in Hindi Python Tutorials Beginners macos installation guide linux SaralGyaan Saral Gyaan json in python JSON to CSV Convert json to csv python in hindi convert json csv in python remove background python mini projects background removal remove.bg tweepy Django Django tutorials Django for beginners Django Free tutorials Proxy Models User Models AbstractUser UserModel convert json to csv python json to csv python Variables Python cheats Quick tips == and is f string in python f-strings pep-498 formatting in python python f string smtplib python send email with attachment python send email automated emails python python send email gmail automated email sending passwords secrets environment variables if name == main Matplotlib tutorial Matplotlib lists pandas Scatter Plot Time Series Data Live plots Matplotlib Subplots Matplotlib Candlesticks plots Tutorial Logging unittest testing python test Object Oriented Programming Python OOP Database Database Migration Python 3.8 Walrus Operator Data Analysis Pandas Dataframe Pandas Series Dataframe index pandas index python pandas tutorial python pandas python pandas dataframe python f-strings padding how to flatten a nested json nested json to csv json to csv python pandas Pandas Tutorial insert rows pandas pandas append list line charts line plots in python Django proxy user model django custom user model django user model matplotlib marker size pytplot legends scatter plot python pandas python virtual environment virtualenv venv python python venv virtual environment in python python decorators bioinformatics fastafiles Fasta python list append append raspberry pi editor cron crontab Cowin Cowin api python dictionary Python basics dictionary python list list ios development listview navigationview swiftui ios mvvm swift environmentobject property wrapper @State @Environm popup @State ios15 alert automation instagram instaloader texteditor youtubeshorts textfield multi-line star rating reusable swift selenium selenium driver requests-html youtube youtube shorts python automation python tutorial algo trading nifty 50 nifty50 stock list nifty50 telegram telegram bot dictionary in Python