Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

string comparison in python

# Comparison is done through "lexicographic" order of letters
# Change the variable 'word' then run and see the results
# Remember a capital letter comes before a simple letter 
word = 'banana'
if word == 'banana':
    print('All right, bananas.')

if word < 'banana':
    print('Your word', word, 'comes before banana')
elif word > 'banana':
    print('Your word', word, 'comes after banana')
else:
    print('All right, bananas.')
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #string #comparison #python
ADD COMMENT
Topic
Name
1+2 =