



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Today ...
Python provides various methods for working with strings
s.upper()
s.lower()
s.count(s2)
s.find(s2)
s.replace(s old, s new)
In Python ord() returns ASCII code, chr() returns character:
ord(’A’) 65
chr(65) ’A’
ord(’a’) 97
chr(97) ’a’
chr(97+1) ’b’
chr(122) ’z’
ord(’\n’) 10
chr(10) ’\n’
chr(97) + chr(98) + chr(99) ’abc’
How can we write a to upper(ch) function?
def to_upper(ch): intval = ord(ch) if intval >= 97 and intval <= 122: return chr(intval - 32) else: return ch