Dealing with strings in Python is very simple: you can search, replace, change character case, and perform other manipulations with ease:
To search for a string, you can use the find method like this:
#!/usr/bin/python3
str = "Welcome to Python scripting world"
print(str.find("scripting"))
![](https://static.packt-cdn.com/products/9781788990554/graphics/assets/409cba04-6f75-4ced-a2a0-f51c08178b79.png)
The string count in Python starts from zero too, so the position of the word scripting is at 18.
You can get a specific substring using square brackets like this:
#!/usr/bin/python3
str = "Welcome to Python scripting world"
print(str[:2]) # Get the first 2 letters (zero based)
print(str[2:]) # Start from the second letter
print(str[3:5]) # from the third to fifth letter
print(str[-1]) # -1 means the last letter if you don't know the length
![](https://static.packt-cdn.com/products/9781788990554/graphics/assets/7d996f4c-71ac-4faa-8e65-b408841d8ae5.png)
To replace a string, you can use the replace method like this:
#!/usr/bin/python3
str = "Welcome to...