Skip to main content

Tutorial 2:Double Quote or Single Quote

Revision
In lesson 1:Hello World Program, we've learnt how to print the words. To print the words, we use the print() function and put the words we want to print between the quotes (either single quotes or double quotes is okay) inside the parenthesis.

Review Exercise 1:Write a program that prints (actually displays) I am Aung Aung using single quotation marks.

Review Exercise 2:Write a program that prints I am Aung Aung using double quotation marks.

Review Exercise 3:Write a program that prints I'm Aung Aung using single quotation marks.

Review Exercise 4:Write a program that prints I'm Aung Aung using double quotation marks.

 Double
quote 
Single Quote 
 I am Aung Aung
 okayokay 
 I'm Aung Aung okayerror 

In Review Exercise 2 and  4, we don't get any error message. We use double quotes inside the parenthesis in Review Exercise 4 so that the computer doesn't confuse. But in Review Exercise 3, we use
print('I'm Aung Aung')
The computer always reads the code from top to bottom and form left to right. There are three single quotes inside the  parenthesis. The computer doesn't know the words it must display. That's why we get error messages. To solve this problem, we must tell the computer that the single quote between I and m must be displayed. To do this, use backlash \. So the code is
>>>print('I\'m Aung Aung')
Run it. We will get the output
I'm Aung Aung

In Python, the sequence of characters(e.g. Hello World) is written inside either the single quotes or double quotes. They can be used interchangeably. To print(display) the single quote use \' . Similarly to print the double quote use \"

Exercise 1:Write a program that print Ko Ko said,"I'm hungry".


Comments