Python注释 转义字符 输出到显示器及文件

作者猫斯基 2020-01-02 242 人读过

最新文章

# Author:猫斯基
# Website:www.maosiji.com

# 输出到显示器
print(520) # 520 不带单引号
print('hello world') # hello world  带单引号
print( 2 + 8 ) # 4
print( 520, 'hello world', 5+8 )    # 520 hello world 13
# 转义字符
print( '他说:'猫斯基在吗?'') # 他说:'猫斯基在吗?'
print( "他说:"猫斯基在吗?"" ) # 他说:"猫斯基在吗?"
print( 'https:\python.www.maosiji.com' ) # https:python.www.maosiji.com
print( 'hello nWorld') # 换行
# hello
# World
print( 'hello tWorld') # 制表符,一个tab是4个空格 hello 	World
print( 'hello rWorld') # 回车,将hello覆盖了  World
print( 'hello bWorld') # 退格,退一个字符串的位置  helloWorld
# R r,原字符输出,如果不希望字符串中的转义符生效,前面加R或r
print( R'https:python.www.maosiji.com') # https:python.www.maosiji.com
print( R'https:python.www.maosiji.com') # https:python.www.maosiji.com
# 8bit = 1byte      8位 = 1字节
# 1024byte = 1kb
# 输出到文件
# 三个引号注释
'''
fp = open( 'D:/python-test.txt', 'a+' ) # a+ 的含义是 以读写的方式打开文件
print( '猫斯基', file=fp )
fp.close()
'''

本文由 猫斯基 原创发布。

著作权均归用户本人所有。独家文章转载,请联系本站管理员。获得授权后,须注明本文地址! 本文地址:https://www.maosiji.com/2644.html

关注我们

站长

WordPress迷