



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These lecture notes cover string functions in python, including uppercase and lowercase conversion, counting and finding substrings, and replacing substrings. It also introduces basic cryptography, discussing the concept and examples of encryption algorithms. The notes include examples and exercises for better understanding.
Typology: Study notes
1 / 6
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