關於python中中文顯示問題__python

來源:互聯網
上載者:User

我在初學python中,輸入中文時會出現中文高亮出錯現象

# coding=utf-8import sysdef Main():    # dict = {'a':'apple', 'b':'banana', 'c':'car', 'd':'dict'}    # print(dict)    # print dict['a']    # dict.pop('c')    # print(dict)    D = {'a':3, 'b':2, 'c':1}    ks = D.keys()    print ks    ks.sort()    for key in ks:        print key, '->', D[key]    for key in sorted(D):        print key, '->', D[key]    if D.has_key('a'):        print D['a']    else:        print '不存在這個索引值'  ///這裡是高亮的if __name__ == "__main__":    Main()

錯誤提示:

C:\Python27\python.exe C:/Users/wys/PycharmProjects/untitled/hello02.py  File "C:/Users/wys/PycharmProjects/untitled/hello02.py", line 83SyntaxError: Non-ASCII character '\xe4' in file C:/Users/wys/PycharmProjects/untitled/hello02.py on line 83, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for detailsProcess finished with exit code 1

解決方案是,把#coding=utf-8放在第一行,一定要是第一行或者第二行,因為我前面有很多注釋,不是第一行,所以就出現這種錯誤,謹記。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.