print输出函数

python的输出函数

  • print()函数可以输出那些内容?
    • print()函数输出的内容可以是数字
    • print(520)

       

       

    • print()函数输出的内容可以是字符串
    • print("hello word!")

       

       

    • print()函数输出的内容可以是含有运算符的表达式
    • print(3+1)

       

       

  • print()函数可以将内容输出的目的地
    • 1,显示器
    • 2,文件
    • #将文件输出到文件中
      fg=open('D:/text.txt','a+')#如果文件不存在就创建,如果文件存在内容的后面就继续追加
      print('helloworld',file=fg)
      fg.close()

      可以在D文件中创建一个text文件中(注意:1,所指定的盘要存在,2,使用file=fg)

    • 不换行输出
    • print("hello","nihao")

       

       

  • print()函数的输出形式
    • 1,执行
    • 2,不执行
posted @ 2021-12-23 23:00  进一步海阔天空  阅读(363)  评论(0编辑  收藏  举报