Strings and Related Operations

Strings represent text in Python and are used constantly, whether you're cleaning messy data, reading file names, or formatting output for a report.

Creating and Indexing Strings

message = "Data Science"
print(message[0])
print(message[-1])
print(message[0:4])

Common String Methods

text = "  Hello World  "
print(text.strip())
print(text.lower())
print(text.upper())
print(text.replace("World", "Python"))
print(text.strip().split(" "))

String Formatting with f-strings

name = "Aditi"
score = 92
print(f"{name} scored {score} marks")

Joining Strings

words = ["Python", "is", "fun"]
sentence = " ".join(words)
print(sentence)
A large part of real-world data cleaning involves string operations like strip(), replace(), and split() to fix inconsistent text entries before analysis.

Coming Up

Next up are sets, a data structure built specifically to store unique values and perform mathematical operations like union and intersection.

Ready to Master Data Science?

Join Uncodemy's Data Science Course and build real, job-ready skills with expert mentors.

Explore Course