2

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"
Neb
2,2801 gold badge15 silver badges28 bronze badges
asked Oct 26, 2018 at 22:51

1 Answer 1

2

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.

answered Oct 26, 2018 at 23:07
Sign up to request clarification or add additional context in comments.

4 Comments

Do you recommend I should strip all variable identifiers from the variables?
I recomment to use only number, letters and underscores. Letters can belong to any alphabets, so ыть it's fine.
I wouldn't really want to read code which has any words and/or characters that aren't plain ascii and exist in English language though. It's fine only as long as you won't share your code with anyone or as long as the project will ever be seen only in your country, e.g. private company project.
@PurpleIce I totally agree with you. Any letter different form a-z would be totally unreadable for me. However, with "it's fine" I meant "It's fine for the compiler/interpreter, since it would not complain" but it is not necessarly a good programming technique

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.