search

Home  >  Q&A  >  body text

python3.x - python open函数中,write方法写入字符串为什么要3个单引号?

阿神阿神2767 days ago639

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-18 10:02:40

    In what environment did you encounter this problem?
    Single quotes are no problem, and I can run it on my own Python 2.7.5.

    m = open('tmp.txt', 'a')
    b = 'nghost'
    m.write(b)
    m.close()

    According to the environment of the questioner, I tried it again and it was ok.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:02:40

    The writing method of three quotation marks is mainly used to avoid string escaping. In python, there are single quotation marks, double quotation marks and three quotation marks. For details, you can check python: single quotation marks, double quotation marks and triple quotation marks. Difference

    reply
    0
  • Cancelreply