t=(22,33,44,55,66,77,88,99) #A tuple is a sequence of immutable Python
print 'Tuple elements : ',t
#Accessing Values in Tuples
print 'Tuple first element :',t[0]
print 'tuple last element :',t[len(t)-1]
print '\n'
for i in t:
print 'Elements in tuple: ',i
print '\n'
for i in range(len(t)):
print 'Index :',i,'Vaule:',t[i]
Solve Problems by Coding Solutions - A Complete solution for python programming
Different indexing in string
fruit='apples'
l=len(fruit)
print 'Length of string:',l
print fruit[0:4] #[m:n] m is starting index and n will upto n-1 index
print fruit[-4] # Index starting from last element as -1, second last element as -2 so on
print fruit[::-1] # Reverse of a string
print fruit[:2]
print fruit[2:]
try:
print fruit[6]
except:
print 'index error'
for i in fruit:
print '\nChar in the string: ',i
for j in range(l):
print '\nIndex and Char in the string: ',j,fruit[j]
l=len(fruit)
print 'Length of string:',l
print fruit[0:4] #[m:n] m is starting index and n will upto n-1 index
print fruit[-4] # Index starting from last element as -1, second last element as -2 so on
print fruit[::-1] # Reverse of a string
print fruit[:2]
print fruit[2:]
try:
print fruit[6]
except:
print 'index error'
for i in fruit:
print '\nChar in the string: ',i
for j in range(l):
print '\nIndex and Char in the string: ',j,fruit[j]
Subscribe to:
Posts (Atom)