Consider the string str="Green Revolution".write statements in python to implement the following:
To display the last four characters.
To display the starting index for the substring 'vo.'
To check whether the string contains 'vol' or not
To repeat the string 3times
Answers
Answered by
31
string = "Green Revolution"
# last 4 chars
string_len = len(string)
last_chars = string[string_len - 4:]
print(f"last 4 chars: {last_chars}")
# starting index of substring "vo"
idx = string.index("vo")
print(f"vo index: {idx}")
# check if "vol" in string
if "vol" in string:
print("vol in string")
else:
print("vol not in string")
# repeat string 3 times
print(string * 3)
Similar questions