⊗pyPmTpCT 73 of 208 menu

Converting to a Tuple in Python

The tuple function allows you to not only create a tuple, but also convert various objects into it, such as strings and lists.

Let's make a tuple from a string:

txt = 'abcde' tpl = tuple(txt) print(tpl) # ('a', 'b', 'c', 'd', 'e')

Given a variable:

tst = ['a', 'b', 'c', 'd']

Convert the contents of a variable to a tuple.

Given a variable:

tst = 'abcde'

Convert the contents of a variable to a tuple.

Given a variable:

tst = 12345

Convert the contents of a variable to a tuple.

byenru