Explanation of knowledge points of tuple function in Python3

  • 2021-09-05 00:30:03
  • OfStack

The functions explained to you in this issue are no strangers, Everyone has encountered and used it, But don't easily feel simple to learn, because often seemingly simple things, from one aspect in-depth collection is a lot of things, don't stay on the surface of cognition, so, in order to let everyone better grasp and understand, the following site integrates related content, give you a detailed introduction to the use, 1 to understand and learn.

Description:

The main function is to convert the list into tuples

Syntax:

tuple()

Parameters:

List

Return value:

Tuple

Usage:


list = ['example_A']
print (list)
tuple = ('example_B',)
print (tuple)
1234

Content supplement

tuple () converts strings, lists, dictionaries, and collections into tuples;


>>> a= 'www'
>>> b=tuple(a)
>>> b
('w', 'w', 'w')
>>> a={'www':123,'aaa':234}
>>> b=tuple(a)
>>> b
('www', 'aaa')  #  When converting fields to tuples, only keys are reserved! 
>>> a=set('abcd')
>>> print (a)
{'c', 'd', 'b', 'a'}
>>> b=tuple(a)
>>> b
('c', 'd', 'b', 'a')

Related articles: