String Creation & Indexing
Strings in Python are sequences of characters. You can create them with single quotes, double quotes, or triple quotes. Every character has a numeric index starting from 0.
Creating Strings
s1 = 'Hello'
s2 = "World"
s3 = '''Triple
quoted'''Indexing
word = "Python"
print(word[0]) # P
print(word[3]) # hNegative Indexing
print(word[-1]) # n (last)
print(word[-2]) # oSlicing
print(word[0:3]) # Pyt
print(word[2:]) # thon
print(word[:4]) # Pyth
print(word[::2]) # Pto (every 2nd char)
print(word[::-1]) # nohtyP (reversed)