Ch2 - Types, Variables and Simple I/O
Module Objectives
Use triple-quoted strings and escape sequences to manipulate text
Make programs do maths
Store data in computers memory
Use variables to access and manipulate that data
Get input from users to create interface programs
Using Quotes Inside Strings
When creating strings we surround them with quotes. Can either be single or double quotes.
>>>print ("Program 'Game Over' 2.0") Program
Program 'Game Over' 2.0
The double quotes above are like bookends. They tell the computer where the string starts and ends, so you can use as many single quotes you want between the "bookends" This would be the same if the bookends were single quotes, you can use as many double quotes between the single quote bookends as you want.
>>>print ('Program "Game Over" 2.0')
Program "Game Over" 2.0
Printing Multiple Values
You can print multiple values with a single call to the print ()
function, just like multiple arguments separated by commas.
>>>print ("Same", "message", "as before")
Same message as before
Specifying a Final String to Print
Specifying the print()
function prints a newline character as a final value (i.e. it returns carriage to a new line >>>
This can be changed and instead of the final string being printed is a newline, you can define what the final sting to print will be. You could specify that a space could be the final character to be printed and not a newline when you call the print ()
function
This would mean a subsequent print ()
function
Last updated
Was this helpful?