Damn
Damn

Reputation: 69

Special characters in identifiers in python 3

If one wanted to create and handle variable in python with charters such as !,-,+,x,m or быть, how could he do it with getting an error? Eg.

!-быть = "hello world"

Upvotes: 2

Views: 804

Answers (1)

Neb
Neb

Reputation: 2280

According to the documentation, Python 3 supports Unicode identifiers. However, it only accepts letters and numbers. Therefore, you can have быть as a variable identifier, but you can't have an exclamation mark in an identifier.

You may wonder why using an exclamation mark is not allowed. Then, suppose it was allowed and you named a variable with the identifier !, i.e. the exclamation mark ! is the name of your variable. Then you could have something like:

!=5 # variable assignment

which is confusing because != encodes for the not-equal operator.

Upvotes: 2

Related Questions