Back

Strings

Q1. What is a String?
Q2.
What is the empty string?
Q3.
If you try to give a string value to a variable using this, you will get an error. Why?

myWord1 = Australia

Q4. Enter the following code and get it working:

1    myWord1 = input('Please enter a word >>> ')
2    print('The length of your word is',len(myWord1))
3    print('The letters in your word are as follows:')
4    for letter in myWord1:
5        print (letter)

Q5. Modify the code above. You have to ask the user for a second word. Then make a new string out of your two words by concatenating them. Finally, print out the length of the new string and all of the characters in the string. 
Q6. Annotate your program. Use the # symbol to add comments in suitable places.
Q7. How did you go about testing your program? Write down some of the tests you did and how you carried them out.
Q8. Many programming languages have a data type for a single character, usually called char. Python doesn't have a data type char. Why?

Back