- 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
- Boost程序庫完全開發指南:深入C++”準”標準庫(第5版)
- JavaScript從入門到精通(微視頻精編版)
- Visual C++程序設計教程
- DBA攻堅指南:左手Oracle,右手MySQL
- Progressive Web Apps with React
- The Android Game Developer's Handbook
- ASP.NET Core 5.0開發入門與實戰
- WebAssembly實戰
- Hands-On Data Structures and Algorithms with JavaScript
- R語言游戲數據分析與挖掘
- UML+OOPC嵌入式C語言開發精講
- iOS應用逆向工程(第2版)
- Visual C++數字圖像處理技術詳解
- Python機器學習基礎教程
- Oracle實用教程