0% found this document useful (0 votes)
10 views2 pages

2

Uploaded by

jondhaleom7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

2

Uploaded by

jondhaleom7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Group A -2nd String operation’s

//code :
def string_copy(string):
"""Copies a string."""
new_string = ""
for char in string:
new_string += char
return new_string

def string_concatenate(string1, string2):


"""Concatenates two strings."""
new_string = string1 + string2
return new_string

def string_check_substring(string, substring):


"""Checks if a substring exists in a string."""
found = False
for i in range(len(string) - len(substring) + 1):
if string[i:i+len(substring)] == substring:
found = True
break
return found

def string_equal(string1, string2):


"""Checks if two strings are equal."""
if len(string1) != len(string2):
return False
for i in range(len(string1)):
if string1[i] != string2[i]:
return False
return True

def string_reverse(string):
"""Reverses a string."""
reversed_string = ""
for i in range(len(string) - 1, -1, -1):
reversed_string += string[i]
return reversed_string

def string_length(string):
"""Calculates the length of a string."""
count = 0
for char in string:
count += 1
return count

# Example usage
string1 = "hello"
string2 = "world"
substring = "world"

print(string_copy(string1))
print(string_concatenate(string1, string2))
print(string_check_substring(string1 + string2, substring))
print(string_equal(string1, string2))
print(string_reverse(string1))
print(string_length(string1))

//OUTPUT:>

You might also like