Question

Why do we pass L[:] to each function, rather than simply passing L? #PYTHON

Why do we pass L[:] to each function, rather than simply passing L? #PYTHON

0 0
Add a comment Improve this question Transcribed image text
Answer #1

first of all L[:] generates a new copy of the list.
when a list is passed to a function, then the function will be able to modify the list that was passed in as an input argument/parameter.
but in case if we don't want some function to modify our original list, we typically use [:] to pass the list into the function.
so, by passing L[:] function won't be able to modify th original list L.
Add a comment
Know the answer?
Add Answer to:
Why do we pass L[:] to each function, rather than simply passing L? #PYTHON
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT