Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare accented variables in Python

I need to write few basic scripts for students in Python, like this one:

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

mia_età = 31
print mia_età

But apparently I cannot use accented characters while declaring variables. Is there any way out?

("mia_età" means "my_age" in Italian and I would like to avoid them to write grammar errors in their firts language while learning Python)

like image 590
Francesco Mantovani Avatar asked May 26 '15 03:05

Francesco Mantovani


1 Answers

Python 1 and 2 only support ASCII alphanumeric characters and _ in identifiers.

Python 3 supports all Unicode letters and certain marks in identifiers.

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

Identifiers are normalized according to NFKC, so you can indifferently write U+0061 LATIN SMALL LETTER A followed by U+0301 COMBINING ACUTE ACCENT, or U+00E1 LATIN SMALL LETTER A WITH ACUTE.

like image 58
Gilles 'SO- stop being evil' Avatar answered Oct 18 '22 00:10

Gilles 'SO- stop being evil'