Python入门——print函数、转义字符、数据类型介绍

@ 爱学习的DUO

1 print()函数

1.1 输出到控制台

1.1.1 输出数字

print(520)  #520

1.1.2 输出字符串

print('hello world')  #hello world

1.1.3 输出表达式

print(3*5)  #15

1.2 输出到文件中

fp=open('D:/pp/chuangjian.txt','a+')  #打开一个文件
print('爱学习的阿朵',file=fp)
fp.close()

在这里插入图片描述

note:
(1)a+表示文件不存在就创建 ,存在的话就在内容上继续追加;
(2)要注明:file=?
(3)路径的盘要存在

2 转义字符

2.1 换行字符 \n

print('good\nluck')
  • 输出结果
    在这里插入图片描述

2.2 tab字符 \t

print('good\tluck')
  • 输出结果
    在这里插入图片描述

3 查看python的key words

import keyword
print(keyword.kwlist)
  • 输出结果
    在这里插入图片描述

4 常见数据类型

4.1 整数型 int

4.2 浮点型 float

4.3 布尔型(True、False)

4.4 字符串型 str

猜你喜欢

转载自blog.csdn.net/qq_40264559/article/details/124544916