all about tuples

 Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec  7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license()" for more information.

>>> ###All about tuples

>>> tuples=(1,2,3,4,5)

>>> tuples

(1, 2, 3, 4, 5)

>>> tuples=1,2,3,4,5

>>> tuples

(1, 2, 3, 4, 5)

>>> ##tuples are immutable :-its value cant be changed but list contained in tuple can be changed

>>> #slicing is possible

>>> tuple=1,2,3,4,5,6,7,8

>>> tuple[::]

(1, 2, 3, 4, 5, 6, 7, 8)

>>> tuple=2,4,6,8

>>> tuple[0]=5

Traceback (most recent call last):

  File "<pyshell#10>", line 1, in <module>

    tuple[0]=5

TypeError: 'tuple' object does not support item assignment

>>> tuple=([1],2,3,4)

>>> tuple[0]=5

Traceback (most recent call last):

  File "<pyshell#12>", line 1, in <module>

    tuple[0]=5

TypeError: 'tuple' object does not support item assignment

>>> tuple[0][0]=5

>>> tuple

([5], 2, 3, 4)

>>> 

Comments

Popular posts from this blog

XAMPP, SQL BASIC COMMANDS

The Minion Game Hackerrank Solution

Arrays - DS | HackerRank Solutions