# Strings can use single quotes (' ') or double quotes (" ")
my_var = ' "Hello" ' my_var2 = " Hello's "
# Strings can also span multiple lines using triple quotes (""" """)
my_longstring = """This is stuff this is stuff on a new line""" print(my_longstring)
# Take a string as an input parameter and return a new string # in the reverse order
def reverse_string(string): backwards = '' for char in string:
# Stores the string in reverse order
backwards = char + backwards
# Stores the string in forwards order #backwards = backwards + char
return backwards
# Search a string for the letter 't' # and return True when we find it or False otherwise
def find_t(string):
# Loop over each character
for character in string:
# Check if the character is equal to 't' (==)
if character == 't':
# We found the letter 't' and we can leave the function # and return True
return True
# We got here only if we never found the letter 't'
return False
# Find vowels in a string (upper or lower case)
def print_vowels(string): for char in string: if char.lower() in 'aeiou': print(char) else: print("CONSONANT")
# Print each letter of a string
def print_letters(string): for char in string: print(char)
# Function calls
print_letters("apple") print(reverse_string("apple2")) print_vowels("HEllo") print(find_t("HelloWorld")) print(find_t("I know I have a t in here somewhere..."))