语法结构:
print(输出内容)
print()函数完整的语法格式:
print(value,...,sep='',end='\n',file=None)
单个值输出:
a=100 b=50 print(a) #输出变量值 print(100) #输出常量 print(a+b) #输出计算结果 print('hello') #单引号 print("world") #双引号 print('''hello world''') #三个单引号 print("""welcome""") #三个双引号
多个值输出,使用逗号隔开:
print(a,b,'输出a和b') #输出多个内容,使用逗号隔开 print('b') #输出b print(chr(98)) #输出b,使用chr()函数转换为ASCII码对应的字母
print(ord('北')) #ord()返回指定字符的ASCII值或Unicode值 print(ord('京')) print(chr(21271),chr(20140))
输出内容到指定文件:
f=open('note.txt','w') #打开文件 w->write print('北京欢迎你',file=f) #将内容写进指定的文件里 f.close() #关闭文件
+连接两个字符串:
print('北京欢迎您'+'2023') # +连接两个字符串
多行内容一行显示:
print('北京',end='-->') #修改end的值 print('欢迎您')
posted on
浙公网安备 33010602011771号