Python学习系列之Print函数(一)

前提:

1、下载安装Python3库文件,安装完成后在本地CMD输入python,回车,显示python版本,即表示安装成功。安装的第一个界面记得勾选自动配置系统参数。

注:目前Python2已经停更,不建议使用

 

 

 2.安装Python编辑工具Pycharm

 

接下来就开始学习啦!

Pycharm中新建项目,项目下新建Python文件,即可编码了。

首先学习Print函数

#Python可以输出数字
print(520)
print(22.66)

#Python可以输出字符串
print('hello world')
print("hello world")

#Python可以输出含有运算符的表达式
print(6+2)

#Python可以输出到文件,'a+'表示如果test.txt文件不存在则在该目录下新建test.txt文件,如果文件已存在则将内容追加到文件中(注:执行完成后在Pycharm控制台不会有任何显示,要去对应的目录下去查看是否有该文件)
fp=open('D:/test.txt','a+')
print('hello world',file=fp)
fp.close()

#不进行换行输出(输出内容在一行当中显示)
print('hello','world','Python')  

#可以进行进制转换 ord是将字符串转换为十进制函数 chr是将二进制转换成字符串
print(chr(0b100111001011000))
print(ord('乘'))

输出结果如下图:

 

 在实际运用中,还有很多转义类的字符需要处理

#转义字符
print('hello\nworld')
print('hello\tworld')
print('helloaaa\tworld')    #\制表符
print('hello\rworld')   #\r覆盖
print('hello\bworld')   #\b退格

print('http:\\www.baidu.com')
print('http:\\\\www.baidu.com')

print('老师说:\'同学们好\'')

#原字符,不希望字符串中的转移字符起作用
print(r'hello\nworld')
#注意事项,最后一个字符不能是反斜杠
#print(r'hello\nworld\')
print(r'hello\nworld\\')

  输出结果如下:

 

posted @ 2020-11-18 15:15  寒冰宇若  阅读(547)  评论(0编辑  收藏  举报