Posted on 28th April 2025|32 views
Can anyone give me some examples of substring
Posted on 28th April 2025| views
Hi kartheeka,
Let me show you three different examples of a substring in python, but there are several ways you can create substrings in python
Method 1:
A program that Slices string:
m = "abcdefghijklmnopqrs"
for l in range(2, 4):
print(l, s[l])
print(l, s[l:l + 2])
print(l, s[l:l + 3])
print(l, s[l:l + 4:2])
print(l, s[l:l + 6:2])
Method 2:
A program that gets substring of one-character:
value = "Mindmajix"
for index in range(0, len(value)):
char = value[index]
print(char)
if char == "M":
print(Hello)
Method 3:
The program which takes substring:
string = "abcdefgh"
male = string[0:2]
Female = string[0:3]
trans = string[0:5]
print(male)
print(female)
print(trans)