Search⌘ K
AI Features

Programs of String Operations

Explore string operation programs in Python to understand copying, concatenation, searching within lists, and reversing strings. This lesson helps you practice manipulating strings through executable code examples and prepares you to handle string tasks in real applications.

Copy a string

In Python, individual characters in a string can be accessed but not assigned or modified.

The following program copies a string to another string:

Python 3.10.4
src = 'Just a string' # The string to be copied
lsrc = len(src) # Calculating the length of src
dst = '' # Creating an empty string
for index in range(lsrc):
dst += src[index] # Copying data from src to dst character by character
print (src)
print (dst)

String concatenation

Concatenation means appending a string to another ...