Skip to content

Instantly share code, notes, and snippets.

@AhmedZahid098
Created May 15, 2018 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AhmedZahid098/0fe00d44f50f1a59d0bc13a2d653ec6d to your computer and use it in GitHub Desktop.
Save AhmedZahid098/0fe00d44f50f1a59d0bc13a2d653ec6d to your computer and use it in GitHub Desktop.
# Tuples are sequences, like lists, but they are immutable, like strings
# Syntactically, they are normally coded in parentheses instead of square brackets,
# and they support arbitrarytypes, arbitrary nesting, and the usual sequence operations.
# A Tuple and its length is as below
T = (1, 'a', 2, 'b', 3, 'c')
print (T)
print(len(T))
# Indexing
print(T[2])
# slicing
print(T[3:])
# Concatination didn't happen
T = T + ()
print(T)
# Method of Tuple --> tuple.index(index) --> didn't work
a = T.index(2)
print(a)
# Method of Tuple --> tuple.count(index) --> didn't work
a = T.count(1)
print(a)
# Cannot grow and shrink the tuples although it is possible use nesting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment