Home › Python Tutorial › Python strings and string formatting
Python strings and string formatting
Slice, search and format text.
Strings can be sliced with [start:end] (end is not included). Methods like upper and replace return a new string. f-strings (f"...") put values straight into text.
Example code
s = "Hello, World"
print(len(s))
print(s.upper())
print(s[0:5])
print(s.replace("World", "Python"))
print("World" in s)
name = "Ada"
print(f"Hi {name}, 2+3={2+3}")