KnowledgeBoat Logo
|

Computer Science

Consider the string str1 = "Global Warming".

Write statements in Python to implement the following:

(a) To display the last four characters.

(b) To replace all the occurrences of letter 'a' in the string with "*".

Python String Manipulation

4 Likes

Answer

(a)

str1 = "Global Warming"
last_four = str1[-4:]
print(last_four)
Output
ming

(b)

str1 = "Global Warming"
replaced_str = str1.replace('a', '*')
print(replaced_str)
Output
Glob*l W*rming

Answered By

2 Likes


Related Questions