- Learn Python in 7 Days
- Mohit Bhaskar N. Das
- 253字
- 2021-07-09 20:40:21
Triple, double and single quotes
Python doesn't care if you use single quotes or double quotes to print a single statement. But, surely, both has some significance while printing complex statements, which we will see soon.
print "Hello World!" and print 'Hello World!' will give the same output Hello World! two times:

How will you print something like this:
print '''I am mad in love
do you think
I am doing
the right thing '''
Alternatively, you can also use double quotes three times to achieve the same thing:
print """I am mad in love
do you think
I am doing
the right thing """
Let's try another example. What should be the outcome of the following statement?
print 'Hey there it's a cow'
The preceding piece of code gives the following results:
C:pydev>python hello.py
File "hello.py", line 1
print 'Hey there it's a cow'
^
SyntaxError: invalid syntax
Python simply interprets that the statement terminated with a single quote after it. The solution is to enclose the complete sentence within double quotes as shown:
print "Hey there it's a cow"
Adding double quotes (") gives an error-free output as shown:
C:pydev>python hello.py
Hey there it's a cow
- Mobile Application Development:JavaScript Frameworks
- Java入門經典(第6版)
- 密碼學原理與Java實現
- Android項目開發入門教程
- Rust編程從入門到實戰
- Java持續交付
- Scala編程實戰(原書第2版)
- SQL Server 2016數據庫應用與開發
- Nginx實戰:基于Lua語言的配置、開發與架構詳解
- Active Directory with PowerShell
- Qlik Sense? Cookbook
- Apache Solr PHP Integration
- HTML5移動Web開發
- Python 快速入門(第3版)
- SQL Server實例教程(2008版)