How to solve empty list and append output to None by Python
This article mainly explains "Python how to solve the empty list to append output to None", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "Python how to solve the empty list append output to None" it!
The function you want to achieve
Number of additions in empty list
Original code:
FitnessBest = [] FitnessBest = FitnessBest.append (fitnessVal [0,0]) print (FitnessBest)
Output:
None
Solution.
Analysis:
Be careful! The append method simply modifies the original list in the right place!
This means that instead of returning a list, he just modifies the original list, so if you use the equation output, the return is None, which means there is no return value!
In other words, remove the return value to get a new list!
Modified code:
FitnessBest = [] FitnessBest.append (fitnessVal [0,0]) print (FitnessBest)
Content supplement:
Analysis of problems
Considerations for using append:
The append method simply modifies the original list in the right place!
That is, instead of returning a list, it just modifies the original list, so if you use equation output, the return is None.
Remove the return value to get a new list!
Modified code:
List= [1, 2, 3, 4] list.append (5) print (list)
Output:
1,2,3,4,5
At this point, I believe you have a deeper understanding of "Python how to solve the empty list appended output to None", might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!