Python_note_001(Python中的输出函数print、转义字符、原字符)

时间:2020-09-17 16:11:27   收藏:0   阅读:32

Python官网:https://www.python.org

PyCharm安装:https://www.runoob.com/w3cnote/pycharm-windows-install.html

Python中的输出函数print()

   1.控制台

   2.文件,写法如下:

1 #"a+"表示的是以读写的方式打开文件,如文件存在就在文件中追加,如不存在就创建文件
2 fp=open(E:/text.txt,a+) 
3 print(hello,file=fp)
4 fp.close()

     1.不换行,如下:

1 print(hello,word,python)

   2.换行,如下:

1 print(hello)
2 print(word)

转义字符

  就是反斜杠+想要实现的转移功能首字母。

  \:转义;\n:换行;\t:水平制表符(四个字符是一个\t);\r:覆盖前面的字符串;\b:去掉前一个字符

1 print(hello\nPython)#换行
2 print(hello\tPython)#输出结果为hello   Python
3 print(hello\rPython)#输出结果为Python
4 print(hello\bPython)#输出结果为:hellPython
5 #注意事项:最后一个字符不能是反斜杠\

原字符

1 #r或者R:使转义字符失效,输出结果为hello\nPython
2 print(rhello\nPython)

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!