作者热门文章
- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我需要为 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/
我是一名优秀的程序员,十分优秀!