Strings and Characters
Strings
Some functions and index methods that can be performed on strings
Action
Function
# strings.py
letter = "b"
word = "good-bye"
subword = "good"
word_length = len(word)
word_first_char = word[0]
word_subword = word[5:8]
print(f"Length of word: {word_length}")
print(f"First letter: {word_first_char}")
print(f"Last three characters: {word_subword}")
print(f"{letter} is in {word}: {(word.index(letter))}")
print(f"{subword} is in {word}: {(subword in word)}")
print(f"remove the last character: {(word[:-1])}")Resources
Last updated
