- 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
- 計(jì)算機(jī)網(wǎng)絡(luò)
- Visual FoxPro程序設(shè)計(jì)教程
- Building Mobile Applications Using Kendo UI Mobile and ASP.NET Web API
- Cassandra Data Modeling and Analysis
- Kotlin Standard Library Cookbook
- Oracle BAM 11gR1 Handbook
- Python:Master the Art of Design Patterns
- Haxe Game Development Essentials
- Python忍者秘籍
- RabbitMQ Essentials
- SQL Server與JSP動(dòng)態(tài)網(wǎng)站開(kāi)發(fā)
- 用戶體驗(yàn)可視化指南
- Android應(yīng)用開(kāi)發(fā)深入學(xué)習(xí)實(shí)錄
- Practical Microservices
- 從零開(kāi)始學(xué)Python大數(shù)據(jù)與量化交易