1. string manipulation.py
word = "Australia" #[start:stop:step] print(word[0]) #A print(word[0:2]) #Au print(word[0::2]) #every 2nd letter till the end print(word[::-1]) #step backwards, from start to end print(word.isupper()) #is upper-case = False print("ABC".isupper()) #True print("abc".islower()) #True print(word.upper()) #AUSTRALIA print(word[::-1].upper()) #AILARTSUA print(word.lower()) #australia if "Aust" in word: print("'Aust' found.") if "xyz" not in word: print("'xyz' has not been found.") if word in word: print("fancy that.") print(len(word)) #9 (i.e. length of word) print(len("a b c")) #5 - includes spaces print(word.count("a")) #2 print(word.lower().count("a")) #3 - no more capitals print(word.replace("a","z")) #Austrzliz #down the page: for eachLetter in "Australia": print(eachLetter) #across the page (no need for this, but yolo): print("".join(c for c in "Australia")) #^^print(item, sep=' ', end='', flush=True) in Python 3
a: 3
e: 1
i: 2
o: 1
u: 1
ord("A")
where "A" is the character i am keen to get the code of (in this case it will be 65). To convert from ASCII value to character, use chr(65)
. Can you write an encoder / decoder that converts a sentence to ASCII code, and back again?