How to create a List in Python?

🎓 Welcome back to Digital Academy, the Complete Python Development Tutorial for Beginners, which will help you Learn Python from A to Z!

🖥️ How to create a List in Python?

There are several ways to create a new list. In Python programming language, the simplest way to create a list is: to enclose all the items, also known as elements, inside square brackets [] – and separated by commas. It can have any number of items inside, and they may even be of different Data Types – integer, float, string, boolean, or even another nested list, which contains other items of different data types, and so forth.

Let’s have a closer look at its syntax, so you can declare your own list. Here is an example, in which you want to store a list of strings. First, Let’s declare an empty list – with empty brackets []. Eventually, you will add all of the strings, so that you can store and then access its values, later on.

     # Empty list
     my_list = []
     
     # List of integers
     my_list = [1, 2, 3]
     
     # List of strings
     my_list = ['red', 'green', 'blue']
     
     # List with mixed data types
     my_list = [1, "Hello", 3.4, True, [1, 2, 3]]

A list containing zero items is called an empty list, and you can create one with empty brackets []. But, you can also use the list() constructor to declare a new list in Python, or even convert other data types – like string or tuples, into a list.

     # Convert string - list
     my_list = list('abc')
     
     # Convert tuple - list
     my_list = list((1, 2, 3))

Let’s play this video, stick around and watch until the end of this video! 👍🏻

– Digital Academy™ 🎓

***

☞ WATCH NEXT:
○ Data Types in Python – https://youtu.be/cweUByxBWiU
○ Operators in Python – https://youtu.be/-wDaVLkKOiU
○ IF Statements in Python – https://youtu.be/CC5seZ6OBJ4
○ FOR Loops in Python – https://youtu.be/JgH-D5DSTho

☞ WATCH MORE:
○ HOW TO Learn Python? Python Tutorial for Beginners [FULL Course] https://youtu.be/9hvnSZPMtuw

📖 Blog: http://digital.academy.free.fr/blog/

📖 Complete Python Development Course for Beginners [PLAYLIST]: http://digital.academy.free.fr/playlist/python-development-for-beginners

🛒 Shopping and Discounts: http://digital.academy.free.fr/store/

#Python #Tutorial #Beginners #Shorts

***

♡ Thanks for watching and supporting ♡
Please Subscribe. Hit the notification bell.
Like, Comment and Share.

***

♡ FOLLOW US ♡
http://digital.academy.free.fr/
https://twitter.com/DigitalAcademyy
https://www.facebook.com/digitalacademyfr
https://www.instagram.com/digital_academy_fr/
https://www.youtube.com/c/DigitalAcademyOnline

♡ SUPPORT US ♡
http://digital.academy.free.fr/join
http://digital.academy.free.fr/donate
http://digital.academy.free.fr/subscribe
https://www.patreon.com/digital_academy
https://www.buymeacoffee.com/digital_academy

***

Copy link
Powered by Social Snap