Replacing
Let's consider one more possible need when we need to replace some parts of the text.
Surely, Python can handle this. There is a built-in method .replace
with 2 required arguments: oldvalue
(what needs to be replaced) and newvalue
(and replaced by what). For example, in the string "Hello, world!" we want to replace world by friend.
12print("Hello, world!") print("Hello, world!".replace('world', 'friend'))
Note
String is an immutable data type in Python, accordingly, the methods we will learn will not change value of string, and will only return a copy of the string.
You can apply
.replace
sequentially (s.replace('a', 'b').replace('c', 'd')
).
Swipe to start coding
Given string topic
"Data Visualization in R". You need to replace Visualization with Manipulation, and R with Python, save the result in new_topic
, and print it.
Lösung
Danke für Ihr Feedback!
single
Fragen Sie AI
Fragen Sie AI
Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen
Awesome!
Completion rate improved to 4.35Awesome!
Completion rate improved to 4.35
Replacing
Let's consider one more possible need when we need to replace some parts of the text.
Surely, Python can handle this. There is a built-in method .replace
with 2 required arguments: oldvalue
(what needs to be replaced) and newvalue
(and replaced by what). For example, in the string "Hello, world!" we want to replace world by friend.
12print("Hello, world!") print("Hello, world!".replace('world', 'friend'))
Note
String is an immutable data type in Python, accordingly, the methods we will learn will not change value of string, and will only return a copy of the string.
You can apply
.replace
sequentially (s.replace('a', 'b').replace('c', 'd')
).
Swipe to start coding
Given string topic
"Data Visualization in R". You need to replace Visualization with Manipulation, and R with Python, save the result in new_topic
, and print it.
Lösung
Danke für Ihr Feedback!
single
Awesome!
Completion rate improved to 4.35
Replacing
Swipe um das Menü anzuzeigen
Let's consider one more possible need when we need to replace some parts of the text.
Surely, Python can handle this. There is a built-in method .replace
with 2 required arguments: oldvalue
(what needs to be replaced) and newvalue
(and replaced by what). For example, in the string "Hello, world!" we want to replace world by friend.
12print("Hello, world!") print("Hello, world!".replace('world', 'friend'))
Note
String is an immutable data type in Python, accordingly, the methods we will learn will not change value of string, and will only return a copy of the string.
You can apply
.replace
sequentially (s.replace('a', 'b').replace('c', 'd')
).
Swipe to start coding
Given string topic
"Data Visualization in R". You need to replace Visualization with Manipulation, and R with Python, save the result in new_topic
, and print it.
Lösung
Danke für Ihr Feedback!