首页 > 编程语言 > 详细

笨办法学Python(第四版)—— 习题 1:第一个程序

时间:2020-05-25 00:26:51      阅读:56      评论:0      收藏:0      [点我收藏+]

习题 1:第一个程序

代码:

ex1.py

print("Hello World")
print("Hello Again")
print("I like typing this.")
print("This is fun.")
print(‘Yay! Printing.‘)
print("I‘d much rather you ‘not‘.")
print(‘I "Said" do not touch this.‘)

输出:

$ python3 ex1.py
Hello World
Hello Again
I like typing this.
This is fun.
Yay! Printing.
I‘d much rather you ‘not‘.
I "Said" do not touch this.

小结:

想要在屏幕上输出字符串,只要将内容用单引号或双引号引用起来。

想要输出单引号,则需要将单引号嵌套在双引号中。反之亦然。

拓展:

其他方式输出单引号或双引号

方法一:用转义字符 \,使 被认为是一个字符

print(‘I\‘d much rather you \‘not\‘.‘)

方法二:三引号
当使用三引号标记字符串时,字符串本身的单引号和双引号都能正常显示

print(‘‘‘I‘d much rather you ‘not‘.‘‘‘)

方法三:Ascii码

print(‘I%cd much rather you %cnot%c.‘ % (39,39,39))

笨办法学Python(第四版)—— 习题 1:第一个程序

原文:https://www.cnblogs.com/nancarp/p/12953567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!