Python list() Built in Function

The list() function is a built-in function that creates a list object from an iterable object. A list object is a collection that is ordered and changeable. You can add, remove, or modify items in a list.

Here are some examples of using the list() function:

# Example 1: Create a list from a string
name = "Alice"
name_list = list(name)
print(name_list)
# ['A', 'l', 'i', 'c', 'e']


# Example 2: Create a list from a tuple
colors = ("red", "green", "blue")
colors_list = list(colors)
print(colors_list)
# ['red', 'green', 'blue']


# Example 3: Create a list from another list
fruits = ["apple", "banana", "cherry"]
fruits_list = list(fruits)
print(fruits_list)
# ['apple', 'banana', 'cherry']


# Example 4: Create an empty list
empty_list = list()
print(empty_list)
# []

If you have any questions about this code, you can drop a line in comment.

Comments

Popular posts from this blog

Python chr() Built in Function

Stock Market Predictions with LSTM in Python

Collections In Python

Python Count Occurrence Of Elements

Python One Liner Functions