Menu Close

Python list() Function

In this article, you will learn about list() built-in function. The list() function is used to create a list object. Before going to this tutorial, We will little about the list and then we will see the list function in python.

What is Python list?

Python list is a collection of items, That are ordered, indexed, changeable or immutable. Python list allow duplicate items as well. Python provide lots of built-in list function that make very easy to work with python list.

Learn Python List and Its Built-in Functions

Python list function

Python list function is a built-in function that is used to create list object.

Syntax

The syntax of list function in Python is.

list(iterable)

Parameter

list function in Python take one parameter.

  • iterable:- iterable is Required. A sequence, collection or an iterator object.

Python list example

Here we will take some examples to understand list function in python.

Example 1:

#Create list object x
x = list()
for i in range(1, 11):
	x.append(i)

print(x)

Output

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Example 2:

#Convert string to list:
a = '1234567'
print(list(a))

Example 3:

#Convert tuple to list:
b = (1, 2, 3, 4, 5, 6, 7)
print(list(b))

Example 4:

#Convert set to list
b = {'Python', 'Java', 'PHP', 'C++', 'C'}
print(list(b))

Conclusion

In this tutorial, you have learned the list function to create a list object. list function in python creates an empty list.
If you like this article, please share and keep visiting for further python built-in function tutorials.

Python built-in function

For more information:- Click Here

Previous Article
Next Article

Was this post helpful?

Related Posts

Leave a Reply