# SOME EXAMPLES WITH STRINGS: print(f'Prefixet f, f-String, formaterar talet 3.1415927 till 3 decimaler:') print(f'{3.1415927 :.3f}\n') print('Eller till 3 decimelr, put right in 8 positions:') print(f'{3.1415927 :8.3f}\n') print("""With so called "triple-quoted strings" a text reach several lines""") # print('\t Gives a tab, while \n gives a line') print('\a ger bell (somewhat irriteting...)\n') print("Use end=' '", end='') print("if you don't want a new line.", ) x=2 print(x, x*2, x+3, x**4, sep=' and also ') # OR sep=', ' OR sep='\n’ namn = 'Svea Lundmark' # print(type(namn)) gives print('\nA FEW EXAMPLES ON FUNCTIONS WITH STRING PARAMETERS:') print('There are', len(namn), 'characters in the string "namn".') print('Make a list of the string "Nils": ', list("Nils")) print('We sort the string: ', sorted(namn)) # returns a sorted list. print('After sorting: ', namn) print('Largest character:', max(namn)) print('\nSOME METHODS IN THE STRING-CLASS:') print('The letter a exists', namn.count('a'), 'times.') print('The letter v on position ', namn.index('v')) print('Make all letter lower case:', namn.casefold()) # print(namn.upper().isupper()) # print('Are are lettters upper case?', namn.isupper()) # False. print('\SOME OPERATORA IN STRINGS: =, +, *, in') print('First concatenate with the + operator:') namn += '–Granström' # + operator: concatenating print(namn) print('Then * operatorn:') namn += 2 * ":-)" # * operator print(namn) print('\nTest the operator "in" ') not_letters = [] for b in namn: if not b.isalpha(): # If b not a letter not_letters.append(b) print('Characters that are not letters:', not_letters)