标签:like hello ike ascii pytho tin class 显示 嵌套
代码:
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))
标签:like hello ike ascii pytho tin class 显示 嵌套
原文地址:https://www.cnblogs.com/nancarp/p/12953567.html