python - 如何在 Python 中声明重音变量

标签 python character-encoding unicode

我需要为 Python 的学生编写一些基本脚本,例如:

#!/usr/bin/python
# -*- coding: utf-8 -*-

mia_età = 31
print mia_età

但显然我不能在声明变量时使用重音字符。有什么办法吗?

(“mia_età”在意大利语中的意思是“my_age”,我想避免他们在学习 Python 时用他们的母语写语法错误)

最佳答案

Python 1 和 2 只支持 ASCII 字母数字字符和 _ in identifiers .

Python 3 支持 identifiers 中的所有 Unicode 字母和某些标记.

#!/usr/bin/python3
# -*- coding: utf-8 -*-
mia_età = 31
print(mia_età)

标识符是 normalized根据 NFKC,因此您可以随意编写 U+0061 LATIN SMALL LETTER A 后跟 U+0301 COMBINING ACUTE ACCENT,或 U+00E1 LATIN SMALL LETTER A WITH ACUTE。

关于python - 如何在 Python 中声明重音变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30450276/

相关文章:

PHP/MySQL 编码

php - 存储数据的奇怪字符编码,旧脚本显示它们很好,新脚本却没有

python - 无法在 Python 2.4 中解码 unicode 字符串

c++ - 如何使用boost::spirit解析UTF-8?

python - 使用转换时 Scikit Learn 分类器加载问题 : Vocabulary wasn't fitted or is empty!

python - 格式错误的 CSV 文件和 Pandas read_csv by chunk

java - UTF-8编码和http参数

python - 循环中的散点图仅绘制第一次迭代

python - 使用flask-wtf queryselectfield进行更具体的SQL查询

string - 判断字符串中的特定字符是长字符还是短字符