Python Lesson 9 – Strings | Dataplexa

Strings in Python

Most real-world software applications work more with text than numbers. Usernames, emails, search queries, chat messages, reports, logs, and API responses are all textual information. Python represents and processes textual data using a powerful data type called a string. Mastering strings is essential because almost every professional Python system depends on text manipulation.

Understanding Strings

A string is a sequence of characters stored together inside quotation marks. Characters include letters, digits, spaces, and symbols. When Python encounters quotation marks, it understands the enclosed content should be handled as text instead of numerical data.


# Creating string variables

platform = "Dataplexa"
course = "Python Programming"
message = "Learning strings"
  • Strings store readable information.
  • Quotation marks define textual values.
  • Each character is internally indexed.

Character Indexing

Python stores characters sequentially. Each character receives an index position starting from zero. Indexing allows programs to access individual characters when validating or analyzing text.


word = "Python"

# accessing characters
print(word[0])
print(word[3])
P h
  • Index starts from 0.
  • Used in parsing and validation systems.

Negative Indexing

Python also allows accessing characters from the end using negative indexes. This helps when working with endings such as extensions or suffix values.


text = "Python"

print(text[-1])
print(text[-2])
n o

String Slicing

Slicing extracts a portion of a string without modifying the original value. Python creates a new substring during slicing operations.


course = "PythonProgramming"

# extracting parts
print(course[0:6])
print(course[6:17])
Python Programming

Finding String Length

Programs frequently validate input size such as password length or usernames. Python provides the len() function to measure total characters.


name = "Dataplexa"

print(len(name))
9

String Methods

Python includes built-in methods that transform strings safely. Strings are immutable, meaning original values remain unchanged.


text = "python learning"

print(text.upper())
print(text.capitalize())
print(text.replace("learning","course"))
PYTHON LEARNING Python learning python course

Combining Strings

Joining multiple strings together is called concatenation. Applications combine messages dynamically using this technique.


first = "Data"
second = "Science"

result = first + " " + second

print(result)
Data Science

Formatted Strings (f-Strings)

Modern Python programs prefer formatted strings because they improve readability and performance while embedding variables into text.


name = "Alex"
score = 95

print(f"{name} scored {score} marks")
Alex scored 95 marks

Real-World Example: Login Message


username = "john_doe"
platform = "Dataplexa"

message = f"Welcome {username} to {platform}"

print(message)
Welcome john_doe to Dataplexa

Practice

What is the starting index position of a string?



Which function is used to measure string length?



Strings in Python are __________.



Quick Quiz

Extracting part of a string is called?





Which method embeds variables directly inside text?





String Concepts Summary

ConceptPurpose
StringStores textual data
IndexingAccess characters
Negative IndexAccess from end
SlicingExtract substring
len()Measure size
MethodsTransform text
f-StringsDynamic formatting

Recap: Strings allow Python programs to understand and manipulate human-readable information efficiently.

Next up: Lists in Python.