Python----print函数基本用法总结

如何输出一个字符串或者数字

print("hello")  //双引号
print('hello')//单引号
print(3 + 1)//数值

输出:

hello
hello
4
Process finished with exit code 0

如何创建一个文件并且在里面写入helloword

fp = open('D:/text', 'a+')
 print('helloword', file=fp)

在D盘中找到text文件里面会有helloword

转义字符\t、\n、\b、\r、\\

print('hell\tworld')
print('hello\tworld')  # /t是四个单元格看做一个
print('hello\rworld')  # \r是回车,只用它的话会覆盖前面的,所有一般都是和\n结合一起用
print('hello\bword')  # \b是back  退后一格

print('http:\\\www.baidu.com')  # 用三个单双引号的区别
print('老师说:\'大家好\'')  # 输出引号,在引号前加

print(r'hello\nworld')  # 不希望转义字符起作用的话前面加个r
print(r'hello\nworld\\')  # 最后的字符不能是一个\,两个可以

输出:

hell	world
hello	world
world
hellword
http:\\www.baidu.com
老师说:'大家好'
hello\nworld
hello\nworld\\

Process finished with exit code 0

ASCIl码和汉字

print(chr(0x31))//0x31转化为ASCLL就是数字1
print(ord('孩'))

输出

1
23401

Process finished with exit code 0

常见的数据量为int、float、bool、str

name = '最好的语言'  
print(name)
print('地址', id(name))
print('类型', type(name))

输出

最好的语言
地址 2600807428144     
类型 <class 'str'>

Process finished with exit code 0

bool类型变量(可以参与加减,但不会改变类型)

f1=True;f2=False;
print(f1,f2,type(f1),type(f2))
print(f1+10,type(f1))

输出

True False <class 'bool'> <class 'bool'>
11 <class 'bool'>

Process finished with exit code 0
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木白CPP

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值