Tuples in python

 Tuple:

  • The tuple data type is used to store the collection of items in unordered and it allows duplicate values same as a list.
  • These items are immutable, that means cannot be changed tuple.
  • It is denoted by parentheses () but if calling the index value means using square brackets [].
  • Its index value is started with 0 and end with list_length-1.

Syntax:

  1. Declaring tuple:

    Variable_name=()

    Example:

    t=()

    Declaring value into the list:

    Variable_name=(item1,item2,...item n)

    Example:

    a=(1000,’Kurshitha’,’female’,450)

Example program for print tuple elements:

  1. a=(5,1,8,3)

    print("Fist value : ",a[0])

    print("Last value : ",a[len(a)-1])

    print("Another method to print last value : ",a[-1])

    print("List of elements : ",a)

Output:

Share:

No comments:

Post a Comment

Popular Posts

Search This Blog

Powered by Blogger.

Service Support

Need our help to Learn or Post New Concepts Contact me

Recent Posts

Service Support

Need our help to Learn or Post New Concepts Contact me