String Operations in Python
Strings in Python are sequences of characters enclosed in quotes.
Python provides many operations and functions to work with strings.
Basic String Operations:
------------------------
1. Concatenation (+) : "Hello" + " World" = "Hello World"
2. Repetition (*) : "Hi" * 3 = "HiHiHi"
3. Length (len) : len("Python") = 6
4. Indexing : "Python"[0] = 'P'
5. Slicing : "Python"[1:4] = 'yth'
6. Membership (in, not in): "th" in "Python" = True
Common String Functions:
------------------------
1. upper() : "hello".upper() = "HELLO"
2. lower() : "HELLO".lower() = "hello"
3. capitalize() : "python".capitalize() = "Python"
4. title() : "python is good".title() = "Python Is Good"
5. strip() : " hello ".strip() = "hello"
6. replace() : "apple".replace("a", "o") = "opple"
7. find() : "hello".find("e") = 1
8. count() : "banana".count("a") = 3
9. startswith() : "python".startswith("py") = True
10. endswith() : "python".endswith("on") = True
11. split() : "a,b,c".split(",") = ['a', 'b', 'c']
12. join() : " ".join(["Hello", "World"]) = "Hello World"
Example Code:
-------------
s = " Hello Python "
print([Link]()) # Removes spaces
print([Link]()) # Converts to uppercase
print([Link]("Hello", "Hi")) # Replaces Hello with Hi
print("Pyt" in s) # Checks if substring exists