1. Strings are everywhere and are crucial in programming. A string in python is:
2. There are several python methods that _____ strings such as replace(), join(), split().
3. In the following code, the output is 'M' and then 'Mr', what would you need to produce an output of 'Moo'?
4. What will the following produce
5. What is this code doing?
6. Splitting and stripping strings is extremely useful - especially when working with files.
7. What is the output of the following code?
8. The "in" and "not in" operators are useful tools. What is the output of the following?
9. If you enter 'GREAT' (in capitals) to the following program, what will the output be?
10. The following are additional methods that can be used on strings. Read through the excerpt and fill in the first blank.
11. The join() method is useful when you have a list of strings that need to be joined together into a single string value
>>> ', '.join(['cats', 'rats', 'bats'])
'cats, rats, bats'
>>> ' '.join(['My', 'name', 'is', 'Simon'])
'My name is Simon'
>>> 'ABC'.join(['My', 'name', 'is', 'Simon'])
'MyABCnameABCisABCSimon'
TRUE
FALSE
12. Analyse the following code and select the statement that is correct.
13. Sometimes you may want to strip off whitespace characters (space, tab, and newline) from the left, right or from both sides of a string. An example is:
14. Fill in the blanks for the following
15. Analyse the following program. If the user enters "open 123" (a space in the middle) access is denied. How do you fix this?
16. The following code puts together two strings but there is no space between the "Mr" and "Moose". What needs to be added to line 3?
17. _________ is the big word which means to link things together. You can do this with strings with the + operator.
18. What does the term 'casting' mean? You'll come across it a lot in programming
19. When would casting be needed in a program?
20. There are plenty of other methods that can be applied to a string including: