Detailed Print – CSKC
Sign In

Search

siteicon
Code Learning#PYTHON#9422 Back

Tuple creation variations

Tuple can also be created directly like lists by item values assignment in a parentheses. Other ways are to use constructor based creations using tuple() function. Single value tuple creation needs an extra comma after the item value.

Source Code

		 

Click to open popup

Run Output

(10, 20, 30)
(10, 20, 30)
()
()
(10,)
(10,)
('A', 'B', 'C', 'D')
(1, 2, 3, 4, 5)
(10, 20, 30)
(1, 2, 3)

Notes

  • The function tuple() is called the constructor, which can be used to convert one form to another..
  • Watch for extra comma ( , ) while created a single item tuple.
  • Tuple concatenation always creates a new tuple without affecting values of the tuple being concatenated.


Suggested Filename(s): tuple_creation.py