Today we will be printing stuff!
1. In a cell, write print(“Okay, let us start!”)
Then press Shift+Enter (run it).
You should get a nice output.
2. In the next cell, write print(‘Okay, let us start!’). Note the single quotation.
Then run it. What do you get
3. You should get the same thing in 2 and 1. Now write print(‘Let’s go!’). Then run it. What do you get?
4. What is the problem in 3? The phrase to print has an apostrophe which Python thinks is the end of the phrase and gets confused. So if you have an apostrophe in your sentence, it is better to print with double quotations. Try it and print Let’s go!
5. If you insist on using single quotations you can use \’ for the apostrophe. Now, try that and print Let’s go!
6. If you had used two print commands in the same cell ( for example while doing 4 ), you will notice that Python moves to a new line after executing the first print command, even if you put two print commands in the same line to save space ( in that case you have to use a semicolon) . Try this by typing print(‘In brightest day, in blackest night’); print (‘No evil shall escape by sight’) in the same line in a cell. Run it
7. Now type print(‘In brightest day, in blackest night’)
print (‘No evil shall escape by sight’)
in two different lines but in the same cell. Run it
8. 5 and 6 shall give you the same result. Now we will do an EXERCISE! Print the following exactly as it is – with all the tabs and indentation.
I wanna be the very best,
That no one ever was!
To catch them is my real test,
To train them is my cause.
I’ll travel across the land,
Searching far and wide –
Each Pokemon to understand
The power that’s inside.
Hint:
You can insert an empty line using print(” “)
Different escape sequences in python:
Escape Sequence Meaning
\t Tab
\\ Inserts a back slash (\)
\’ Inserts a single quote (‘)
\” Inserts a double quote (“)
\n Inserts a ASCII Linefeed (a new line)
From <https://stackoverflow.com/questions/4488570/how-do-i-write-a-tab-in-python>