codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🐍

Python Programming

11 / 68 topics
7Python Data Types Overview8Python Numbers & Math9Python Type Conversion (Casting)10Python Booleans & None11Python Strings & Methods12Python String Formatting13Python Operators & Precedence
Tutorials/Python Programming/Python Strings & Methods
🐍Python Programming

Python Strings & Methods

Updated 2026-05-15
30 min read

Python Strings & Methods

In this tutorial, you'll explore the fundamental aspects of working with strings in Python. Strings are one of the most commonly used data types in programming, and mastering them will significantly enhance your ability to manipulate text data. Whether you're processing user input, generating reports, or performing data analysis, understanding strings is crucial.

Introduction

Strings in Python are sequences of characters enclosed within quotes. They can be created using single (' '), double (" "), or triple (''' ''' or """ """) quotes. Strings are immutable, meaning once they are created, their content cannot be changed. This immutability has implications for how you manipulate strings and why certain methods return new strings instead of modifying the original ones.

String Creation

You can create a string using single, double, or triple quotes:

string_creation.py
1single_quoted_string = 'Hello, World!'
2double_quoted_string = "Hello, World!"
3triple_quoted_string = """This is a multi-line
4string."""
Terminal
Output
Hello,
World!

String Indexing

Strings in Python are zero-indexed, meaning the first character is at index 0. You can access individual characters using square brackets:

string_indexing.py
1greeting = "Hello"
2first_char = greeting[0]
3last_char = greeting[-1] # Negative indices count from the end
Terminal
Output
Hello
dlroW ,olleH

Immutability

Strings are immutable, meaning you cannot change them in place. Any operation that seems to modify a string actually creates a new string:

string_immutability.py
1greeting = "Hello"
2try:
3 greeting[0] = 'h' # This will raise an error
4except TypeError as e:
5 print(e)
Terminal
Output
HELLO, WORLD!
hello, world!

strip()

Removes leading and trailing whitespace:

string_strip.py
1text = " Hello, World! "
2stripped_text = text.strip()
Terminal
Output
['Hello', 'World!']

join()

Joins a list of strings into a single string with a specified separator:

string_join.py
1words = ["Hello", "World"]
2sentence = ", ".join(words)
Terminal
Output
Hello, Python!

find()

Returns the lowest index of a substring if found, otherwise returns -1:

string_find.py
1greeting = "Hello, World!"
2index = greeting.find("World")
3not_found_index = greeting.find("Universe")
Terminal
Output
['hello,', 'world!', 'how', 'are', 'you?']

Summary

  • Strings in Python are sequences of characters created using quotes.
  • They are immutable, meaning they cannot be changed in place.
  • Key string methods include upper(), lower(), strip(), split(), join(), replace(), and find().
MethodDescription
upper()Converts the string to uppercase.
lower()Converts the string to lowercase.
strip()Removes leading/trailing whitespace.
split()Splits the string into a list.
join()Joins a list of strings.
replace()Replaces substrings.
find()Finds the index of a substring.

What's Next?

In the next tutorial, we'll explore how to format strings using f-strings, which provide a concise and readable way to embed expressions inside string literals. Understanding string formatting is essential for generating dynamic text in your applications.

Stay tuned!


PreviousPython Booleans & NoneNext Python String Formatting

Recommended Gear

Python Booleans & NonePython String Formatting