# # 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 decimals, right placed in 8 positions:') # print(f'{3.1415927 :8.3f}\n') # # # print("""With so called "triple-quoted strings" a text # reaches several lines""") # # print('\t Gives a tab, while \n gives a line') # print('\a rings a 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 "Svea Lundmark".') # 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.lower()) # print('The methods do not change the original string:', namn) # # print('Are are letters upper case?', namn.isupper()) # False. # # # print('\nSOME OPERATORS ON STRINGS: =, +, *, <, >, in') # print('First concatenate with the + operator:') # namn += '–Granstroem' # + 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)