search

Home  >  Q&A  >  body text

如何让python支持中文

初入python,在python中写入中文注释。之后python就报错(在字符串中写中文也会这样,所以求帮助)

伊谢尔伦伊谢尔伦2768 days ago761

reply all(5)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:21:40

    You just need to add:

    at the beginning of the file
    # -*- coding: utf-8 -*-

    or:

    # coding: utf-8

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:21:40

    If you want to write Chinese in the py file of python2,
    The first or second line
    should add the following line of comments declaring the file encoding, otherwise python2 will use ASCII encoding by default.

    #-*- coding:utf-8 -*-

    Optional formats are

    # -*- coding: <encoding name> -*- 

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:21:40

    coding:gbk

    reply
    0
  • PHP中文网

    PHP中文网2017-04-18 09:21:40

    Add at the top of each file that needs to support Chinese: #coding:utf-8

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 09:21:40

    Read official PEP263

    reply
    0
  • Cancelreply