目录
1、输出多个变量
print(变量1,变量2,变量3,‘\t’)
a = '''aasdf''' b= 5 print(a,'\t',b)
2、增加占位符
name='Jim' age=19 height=172.3 print("My name is %s,my age is %d,my height is %.2f" %(name,age,height))
3、格式化输出
import sys sqlstmp = ''' insert overwrite table target_table select * from sourse_table where l_date = %s '''% sys.argv[1] print(sqlstmp)
4、python3.6版本支持 f-string 格式
name='Jim' age=19 height=172.3 print(f"My name is {name},my age is {age},my height is {height :.2f}")
更改输出管道
with open("a.txt","w",encoding='utf-8') as f: f.write("1234\n") print("asdf",file=f) f.close()