How to Use tuple() Function in PythonPython Basics


The tuple() function is a built-in function that is used to create a tuple object.

Example

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

list1= ['Harvard', 'UCI', 'ZZU', 'MIT']
print(list1)
tuple1 = tuple(list1)
print(tuple1)

Output:

['Harvard', 'UCI', 'ZZU', 'MIT']
('Harvard', 'UCI', 'ZZU', 'MIT')

Syntax

tuple(object)

Parameters

Name Description
object A sequence, collection or an iterator object

Return Value

It returns a tuple object.

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