Legacy - Creating Lists Workout
- 02:46
Learn how to create and manipulate lists in PyCharm.
Downloads
Creating Lists - Python Workout FilesTranscript
Let us now look at how to create lists in Python and how to apply some functions to the lists, we have a list of terms given on the screen, the first job is to run the list. So because this is the first time we are writing this code, we would have to right click on the tab and go to run. So the process has exited without any errors. That's what the zero stands for. Now, in order to get the first of the list views, you have to select the name of the list, square bracket zero. Note that the Python indexing starts from zero rather than one. In order to run this code, we would have to press Shift f9. Again, no errors give it out, meaning it's perfect. But in order for the output to be pasted at the bottom of the page in the output console, we would have to use the print function which prints the value in Python. And again, we would have to run the code which outputs it NPV, which is correct, the first term of the list is NPV. Now in case we want the second term of the list, we do the same thing. But now we ask for one, because that's the second term, perfect, paste DCF. Just right. Now if we want to add a term into the list, we use the append function. So add the name of the list dot append. And we include the word that needs adding in quotations. And we run it so it exited without any error meaning the code is perfect. Now if you want to view the list, we just asked by the print terms and run the code. So we can see that whack has been added to the list. Now in case we want to remove the term WACC from the list, we just say term stock removal, we use the Remove function and say WACC in the quotations. Now if we again print the Terps we can see that WACC has been removed from the new output. But if we feel like deleting the whole list, we just use the DEL function. The code has been executed without any error meaning that's perfect. Now, the key point is if we ask Python to print the terms, it should return an error because we don't have the terms list anymore because we have deleted it. Perfect named terms is not defined meaning the list doesn't exist anymore.