Creation and accessing values in Tuples

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]
   






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]


Compare the two string based on ascii values

str1=raw_input('Enter the string 1:  ')
str2=raw_input('Enter the string 2:  ')
if str1==str2:
      print 'String are equal'  # It is working based on ascii value  refer http://www.ascii-code.com/
elif str1<str2:
      print 'Str2 is greater than str1'
elif str1>str2:
        print 'Str1 is greater than str2'
elif str1<=str2:
        print 'Str1 is greater than or equal to str2'
elif str1>=str2:
        print 'Str1 is greater than or equal to str2'
elif str1!=str2:
        print 'Str1 is not equal to str2'

Converting a for loop to corresponding while loop

for count in range(0,100,2):
   print 'For:',count

count1 =0
while(count1<100):
  print 'While:',count1
  count1=count1+2

Evaluating expression in Python

x=2
y=3
z=2

print x**y**z  #Answer 512

print (x**y)**z  #Answer 64

print x**(y**z)  #Answer 512