PMDS508L - Python Programming
Module – 4 – Data Collections
Prepared by: Dr. Nandhini S, SAS
Topics covered:
• Strings
• Regular Expressions
Table of string operations
Operation Syntax Example Output
Length of String len(s) len("India") 5
Slicing s[start:end:step] "Python"[1:5:2] yt
Uppercase [Link]() "hello".upper() HELLO
Lowercase [Link]() "HeLLo".lower() hello
Title Case [Link]() "hello world".title() Hello World
Swap Case [Link]() "Hello".swapcase() hELLO
Strip [Link]() " hello ".strip() hello
Find Substring [Link]("sub") "banana".find("na") 2
Replace Substring [Link]("a", "o") "apple".replace("a","o") opple
Split [Link](sep) "a,b,c".split(",") ['a', 'b', 'c']
Join 'sep'.join(list) "-".join(["a","b","c"]) a-b-c
Check isalpha() [Link]() "abc".isalpha() True
Check isdigit() [Link]() "123".isdigit() True
Startswith [Link]("py") "python".startswith("py") True
Endswith [Link]("on") "python".endswith("on") True
==================== END ====================