Electron microscopy
 
PythonML
.replace()
- Python Automation and Machine Learning for ICs -
- An Online Book: Python Automation and Machine Learning for ICs by Yougui Liao -
Python Automation and Machine Learning for ICs                                                           http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

Example 1:
      Original string:
            text = "Hello world"
      Goal: We want to replace the substring "world" with "Python".
      Python code :
            new_text = text.replace("world", "Python")
            print(new_text)
      Output string:
            Hello Python

Example 2:
      Original string:
            text = "Hello world, world is great"
      Goal: We only want to replace the first occurrence of a substring. In this case, the .replace() method takes an optional third argument, which specifies the maximum number of occurrences to replace.
      Python code:
            text = "Hello world, world is great"
            new_text = text.replace("world", "Python", 1)
            print(new_text)
      Output string:
            Hello Python, world is great
    
     
            
            

 

===========================================

         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 



















































 

 

 

 

 

=================================================================================