Python Basics
Strings
Strings are text, written in single or double quotes.
first = "Sara"
last = 'Khan'
full = first + " " + last # join with +
print(full)
print(len(full)) # number of characters
print(full[0], full[-1]) # first and last character
print(full[0:4]) # slicing: "Sara"Output
Sara Khan 9 S n Sara
f-strings
Put an f before the quotes and you can write variables directly inside { }.
name = "Bilal"
marks = 87.456
print(f"{name} scored {marks:.1f} marks")Output
Bilal scored 87.5 marks
Multi-line strings
message = """Dear student,
Welcome to TechSnow!"""