Defining unicode variables in Python

后端 未结 2 775
刺人心
刺人心 2021-01-20 20:58

Recently, I have been reading about the Python source code encoding, especially PEP 263 and PEP 3120.

I have the following code:

# coding:utf-8

s =          


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-20 21:33

    I don't think that those two articles are about encoding in the sense of your variable name being a Beta-symbol for example, but regarding the encoding in the variable value.

    so if you change your code to this example:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    a = 'abc?´ƒ©'
    b = 'My name is'
    c = '°ß?ˆ†ˆ? ßå®åø©ˆ'
    print 'a =', a # by the way, the brackets are only used in python 3, so they are also being displayed when running the code in python 2.7
    print 'b =', b, 'c =', c 
    

    Hope that answers your question

    Greetings Frame

提交回复
热议问题