Python Program to Replace All Occurrences of ‘a’ with $ in a String

This is a Python Program to replace all occurrences of ‘a’ with ‘$’ in a string.

Problem Description

The program takes a string and replaces all occurrences of ‘a’ with ‘$’.

Problem Solution

1. Take a string and store it in a variable.
2. Using the replace function, replace all occurrences of ‘a’ and ‘A’ with ‘$’ and store it back in the variable.
3. Print the modified string.
4. Exit.

Program/Source Code

Here is source code of the Python Program to replace all occurrences of ‘a’ with ‘$’ in a string. The program output is also shown below.

string=input("Enter string:")
string=string.replace('a','$')
string=string.replace('A','$')
print("Modified string:")
print(string)
Program Explanation

1. User must enter the string and store it in a variable.
2. The replace function replaces all occurrences of ‘a’ and ‘A’ with ‘$’ and store it back in the variable.
3. The modified string is printed

advertisement
Runtime Test Cases
 
Case 1:
Enter string:Apple
Modified string:
$pple
 
Case 2:
Enter string:Asia
Modified string:
$si$

Sanfoundry Global Education & Learning Series – 1000 Python Programs.

If you wish to look at all Python Programming examples, go to 1000 Python Programs.

🎓 Free Certifications on 300 subjects are live for January 2026. Register Now!

👉 For weekly programming practice and certification updates, join Sanfoundry’s official WhatsApp & Telegram channels

advertisement
Manish Bhojasia – Founder & CTO at Sanfoundry

I’m Manish, Founder & CTO at Sanfoundry, with 25+ years of experience across Linux systems, SAN technologies, advanced C programming, and building large-scale, performance-driven learning and certification platforms focused on clear skill validation.

LinkedIn  ·  YouTube MasterClass  ·  Telegram Classes  ·  Career Guidance & Conversations