当前位置:网站首页>The solution to prompt "this list creation could be rewritten as a list literal" when adding elements to the list using the append() method in pychart

The solution to prompt "this list creation could be rewritten as a list literal" when adding elements to the list using the append() method in pychart

2022-06-23 04:53:00 Haohong image algorithm

stay Pycharm Use in append() Method to add elements to the list "This list creation could be rewritten as a list literal", The screenshot is as follows :
 Insert picture description here
"This list creation could be rewritten as a list literal.” It means that the creation of this list can be rewritten more easily .

What do you mean ?
Let's look at the above two lines of code :

list1 = ['Google', 'CSDN', 'tencent', 1997, 1999, 1998]
list1.append(2000)

You can see , Because there is no operation in the middle , therefore Pycharm Judge that the two sentences of code can be combined into the following statement :

list1 = ['Google', 'CSDN', 'tencent', 1997, 1999, 1998, 2000]

So it makes a hint in the title “This list creation could be rewritten as a list literal”.
How to make it disappear ? It's simple , Add any statement between two sentences of code , Like the following :

list1 = ['Google', 'CSDN', 'tencent', 1997, 1999, 1998]
kkk = 1
list1.append(2000)

 Insert picture description here
From the screenshot above, we can see , The prompt is gone .

原网站

版权声明
本文为[Haohong image algorithm]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206222354113698.html