Tech
"5 Python mistakes I keep making as a beginner (and how I fixed them)"
## 1. Using return instead of print inside a loop
This one bit me early on. I wanted to print every item in a list, so I wrote something like this:
python
def show_items(items):
for item in items:
return item
show_items(["apple", "banana", "cherry"])
Run it, and... nothing prints. Why? return doesn't just output a value it immediately exits the function. So the loop runs exactly once, hands back "apple", and the function is done. banana and cherry never gets a chance....
Read the full discussion on Dev.to
This article was aggregated from Dev.to. Click to join the conversation.
View on Dev.to