Member-only story

Python 101 — Intro to Manipulation, String Manipulation

Adina Socaci
7 min readSep 10, 2023

--

Python offers a rich set of tools for manipulating strings, allowing you to perform various operations like concatenation, slicing, formatting, and searching. In this technical explanation, I’ll cover some essential string manipulation techniques.

Creating Strings

In Python, you can create strings using single, double, or triple quotes:

single_quoted = 'This is a single-quoted string.'
double_quoted = "This is a double-quoted string."
triple_quoted = '''This is a triple-quoted string.'''

String Concatenation

You can combine (concatenate) strings using the + operator:

str1 = "Hello"
str2 = "World"
result = str1 + " " + str2 # "Hello World"

String Indexing and Slicing

Strings are indexed from 0, and you can access individual characters or substrings using square brackets:

my_string = "Python"
char = my_string[0] # 'P'
substring = my_string[2:5] # 'tho'

String Length

To find the length of a string, you can use the len() function:

my_string = "Python"
length = len(my_string) # 6

--

--

Adina Socaci
Adina Socaci

Written by Adina Socaci

Tech | Science | Languages | Having Fun

No responses yet