Can variable names be in Chinese? Just blinded people

It started like this
insert image description here
. In the morning, the editor went to the library to study as usual. When I passed by a girl, I glanced at it and found that she was also learning python, but the two lines of code displayed on the screen directly confused people. up! The content is as follows:

用户输入 = input('请输入内容:')
print(用户输入)

insert image description here

Just thought, can Chinese be used as variable names in python?

insert image description here
In fact, I really wanted to talk to her about this problem at the time, but I was afraid that I would not have enough knowledge. What if it really works? So, I found a small corner with no one, and I was going to try it myself!

I took those two lines of code intact, and found that it really works, because I have never done this before!

But I still don't believe it, and tested the following code like a cat and a tiger

字符串 = '隔壁老王'
元组 = ('哈哈', '嘻嘻', '你好', '是的')
列表 = ['哈哈', '嘻嘻', '你好']
字典 = {
    
    '姓名': '老王', '年龄': '二十五岁', '性别': '男'}
集合 = {
    
    '二哈', '阿拉斯加', '萨摩耶'}
print(字符串)
print(元组)
print(列表)
print(字典)
print(集合)

隔壁老王
('哈哈', '嘻嘻', '你好', '是的')
['哈哈', '嘻嘻', '你好']
{
    
    '姓名': '老王', '年龄': '二十五岁', '性别': '男'}
{
    
    '二哈', '萨摩耶', '阿拉斯加'}

老王的年龄 = 18

用户输入 = input('请输入你猜的老王的年龄:')
if int(用户输入) == 老王的年龄:
    print('恭喜您猜对了!!!')
elif int(用户输入) > 老王的年龄:
    print('您猜的年龄偏大了!!')
else:
    print('您猜的年龄偏小了!!!')

请输入你猜的老王的年龄:23
您猜的年龄偏大了!!

insert image description here
Although the colors displayed in pycharm are not correct, there is no problem with the operation.

So the question is, is this really the right thing to do?
insert image description here
the answer is negative,inappropriate. Not to mention anything else, in the process of writing the above code, I feel that the frequency of switching input methods has increased significantly! In fact, this is only secondary!

The main ones are here →The editor warmly reminds me here that the variable names in python should not be named in Chinese (Pinyin is not suitable), do not use Chinese (Pinyin is not suitable), do not use Chinese (Pinyin is not suitable, as little as possible in the code) Appear Chinese)! ! ! Use English for the name, it is best to see the name uprising, so that others can guess the approximate meaning of it at a glance! (For example: use name for name, use age for age, etc.)

Due to the increasing popularity of python in recent years, it has become more and more robust, flexible, and efficient, but don't misinterpret the original meaning of "Uncle Turtle" by naming variables in Chinese!

Guess you like

Origin blog.csdn.net/hpl980342791/article/details/116370015