如何输出一个字符串或者数字
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