How to Use List Construct Method in PythonPython Basics


The list() function creates a list object which is ordered and mutable.

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

Tuple1 = (2019, 'Google', 'MIT', 'UCI')
list1 = list(Tuple1)
print(list1)

str1="ABCDEF"
list2=list(str1)
print(list2)

Output:

[2019, 'Google', 'MIT', 'UCI']
['A', 'B', 'C', 'D', 'E', 'F']

Syntax

list(obejct)

Parameters

Name Description
object A sequence, collection, or an iterator object.

Return Value

It returns a list object.


Syntax

Example

#!/usr/bin/python3
# -*- coding: UTF-8 -*-

list1 = ['MIT', 'UCI', 1997, 2019]
list2 = [1, 2, 3 ]
list3 = ["a", "b", "c"]
listname = []

Parameters

The method doesn’t take any parameters.

Return Value

It doesn’t return any values.

© 2024 Cheerlearn.com, all rights reserved. Privacy Policy | Contact Us