string = 'starry sky'
print(string.find('a'))
line = 'Kate on her skateboard!'
print(line.find('Kate'))
line = 'Kate on her skateboard!'
print(line.find('Katie'))
line = 'Kate on her skateboard!'
print(line.find('ate'))
#there are 2 ""ate"" substrings in variable line, but python shows the starting index of the first occurence.
replace() function
replace()
Β
functionΒ
replacesΒ
aΒ
specifiedΒ
characterΒ
orΒ
substringΒ
withΒ
anotherΒ
inΒ
aΒ
string.
WeΒ
canΒ
alsoΒ
specifyΒ
theΒ
numberΒ
ofΒ
times
Β
theΒ
characterΒ
orΒ
substringΒ
needsΒ
toΒ
beΒ
replaced.
IfΒ
countΒ
isΒ
notΒ
specifiedΒ
pythonΒ
replacesΒ
allΒ
theΒ
occurrences
string.replace('oldWord','newWord',count)
#oldWord is a word you want to replace#newWord is a word you want to replace with#count is the number of times you want to replace oldWord with newWord
line = "Oβreally? bababa!"
print(line.replace('ba', 'ha'))
line = "Oβreally? bababa!"
print(line.replace('ba', 'ha', 2))
#We can also replace two words in one go
line = 'I saw Dave on his bicycle.'
print(line.replace('Dave', 'Donna').replace('his', 'her'))
Sign In
You will receive an OTP for verification purposes.
Our Result
Sanatan is our in-house coding prodigy who ranked as a Top 2 finalist in Googleβs Code-In competition (now defunct). Heβs a great example of how starting early in your coding journey can be so empowering that you can even find yourself tackling challenges at tech giants like Google!
What the world says about Tekie
βWhile most competing platforms are teaching students block-based programming, Tekie is attempting to teach young students the fundamentals of text-based programming, which is to write actual coding language syntax.β
The founder elaborates, βWe came up with the idea of animation because that helps bring imagination to reality. We also wanted to make learning interesting and engaging.β
Parents trust us.
The best learning happens when you are not learning, you are playing and enjoying. For Medha, learning has been a pleasant glide, thanks to a warm and interpersonal method of teaching; it's like she is learning from a friend who knows her! She loves the puzzles and other methods used- both experimental and classic.