STRING – COMPLETE PYTHON NOTES
1. What is a String?
A string is a sequence of characters enclosed in quotes. Immutable and ordered.
2. Creating Strings (5 Ways)
1. s = 'Hello'
2. s = "Hello World"
3. s = '''multi
line'''
4. s = str(123)
5. s = ""
3. Properties of Strings
1. Ordered
2. Immutable
3. Iterable
4. Indexing allowed
5. Slicing possible
6. Supports special characters
7. Rich built■in methods
4. Operations on Strings
1. Concatenation: "hello" + "world"
2. Repetition: "ha"*3
3. Slicing: s[1:4]
4. Membership: 'a' in s
5. Comparison: "abc" < "xyz"
6. Length: len(s)
7. Iteration: for c in s
5. String Methods
A) Case Conversion
upper(), lower(), title(), capitalize(), swapcase()
B) Search & Replace
find(), rfind(), index(), count(), replace()
C) Validation
isalnum(), isalpha(), isdigit(), isspace(), islower(), isupper()
D) Alignment
center(), ljust(), rjust()
E) Splitting & Joining
split(), rsplit(), splitlines(), join()
F) Formatting
format(), f-strings, % formatting
Example Block:
s = "rakshita"
print([Link]())
print([Link]("a"))
print("-".join(["A", "B", "C"]))