Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

1/30/2021 Python for O&G Lecture 13- Strings are Immutable - Colaboratory

Python for Oil and Gas

Website - https://petroleumfromscratchin.wordpress.com/

LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch

YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw

pfs = 'Python from Scratch'

pfs.title()

'Python From Scratch'

print(pfs)

Python from Scratch

pfs.find('f')

7
/
1/30/2021 Python for O&G Lecture 13- Strings are Immutable - Colaboratory

pfs[7]

'f'

pfs[7] = 'F'

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-7-908ba4bf1f37> in <module>()
----> 1 pfs[7] = 'F'

TypeError: 'str' object does not support item assignment

SEARCH STACK OVERFLOW

pfs.replace('f', 'F')

'Python From Scratch'

print(pfs)

Python from Scratch

var = pfs.replace('f', 'F')

print(var)

Python From Scratch

/
1/30/2021 Python for O&G Lecture 13- Strings are Immutable - Colaboratory

You might also like