PYTHON QUESTION a5 ba10 a is now 5555555555 How do you repla

PYTHON QUESTION:

a=\"5\"

b=a*10

a is now 5555555555

How do you replace particular position in a with another substring?

For example, I want the 3rd position of a to be 9. Like, 5595555555.

I tried replace, and it doesnot work

Solution

I will suggest two ways, use which ever seems gooood

1.    say we want to change ith element of string A to char c, (   ith starts from 0 till length(A)-1 )

A = A[:i] + c + A[i+1:]

2.                 L = list(A);   

L[i] = c;  

A = \"\".join( L )

PYTHON QUESTION: a=\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site