Labs ICT
๐ŸŽ“ SIWES/IT Login

Strings

1 min read | Python Tutorial
๐ŸŽ“

Doing SIWES / IT attachment?

Get a structured training programme, a supervised digital logbook, and a completion certificate with LabsICT SIWES / IT.

Explore SIWES / IT Training

Creating Strings

Strings can be created with single quotes, double quotes, or triple quotes for multi-line strings. They all work the same way.

single = 'Hello'
double = "World"
multi = """This is
a multi-line
string"""
print(single)
print(double)
print(multi)

Indexing and Slicing

Strings are sequences, so you can access individual characters by index (starting from 0) and slice them with the [start:end] syntax.

text = "Python"
print(text[0])
print(text[-1])
print(text[0:3])
print(text[:3])
print(text[3:])
print(text[::-1])

String Methods

Python strings come with a rich set of built-in methods for transformation, searching, and formatting. They never modify the original string โ€” they return a new one.

msg = "  Hello, Python World!  "
print(msg.lower())
print(msg.upper())
print(msg.strip())
print(msg.replace("World", "Universe"))
print(len(msg))
print(msg.split())

f-Strings

f-Strings let you embed expressions directly inside string literals using curly braces. They're the modern way to format strings in Python.

name = "Alice"
age = 30
score = 95.5
print(f"Name: {name}")
print(f"Age: {age}")
print(f"Score: {score:.1f}%")
print(f"Next year you'll be {age + 1}")

๐Ÿงช Quick Quiz

What is string interpolation in Python 3.6+ called?