How to Create an Empty List in Python?

How to Create an Empty List in Python?

Python ? Create an Empty List

To create an empty List in Python, we can use list() built-in function with no argument passed to it or take empty square brackets and assign it to a variable. The syntax to crate an empty Python List using list() function is

myList = list()

The syntax to create an empty Python List using square brackets is

myList = []

Example 1 ? Create Empty List using list() function

In this example, we will create an empty list using list() builtin function. We shall print the type of the object returned by list() and print the object itself. Python Program

myList = list() print(type(myList)) print(myList)

Output

[]

Example 2 ? Create Empty List using Square Brackets

In this example, we will create an empty list with empty square brackets. Python Program

myList = [] print(type(myList)) print(myList)

Output

[]

Conclusion

In this Python Tutorial, we learned how to create an empty Python List with the help of example programs.

Python Programming

Python Tutorial Install Python Install Anaconda Python Python HelloWorld Program Python Variables Python Variable Data Type Conversion Python Comments

Control Statements

Python If Python If Else Python While Loop Python For Loop

Python String

Python String Methods Python String Length Python String Replace Python Split String Python Count Occurrences of Sub-String Python Sort List of Strings

Functions

Python Functions

Python Collections

Python List Python Dictionary

Advanced

Python Multithreading

Useful Resources

Python Interview Questions

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download