Can somebody explain the output of this code snippet

0 votes

Can anybody explain me the output of the below code ?

a=[ [7,8], 9, 9]

b=a[:]

a[2]= 200

a[0][1]=17

print (a)

print (b)

Output

[[7, 17], 9, 200]
[[7, 17], 9, 9]
Jun 23, 2020 in Python by anonymous
• 6,260 points
1,436 views

1 answer to this question.

0 votes
By making a copy of a list through slicing which is b=a[:]

So any change in a will not affect to b unless there is no nested values inside a.

If so any changing in that nested value will affect to b too.

This is a demonstration of pass by "object" reference.
answered Jun 23, 2020 by Ya Sd

Related Questions In Python

0 votes
1 answer

Need help with the output of a code snippet.

If you write x.insert(2,3) and then print x ...READ MORE

answered Jun 23, 2020 in Python by Viraj Doshi
3,110 views
0 votes
1 answer

What is the output of the following python code snippet?

for i in range(0, 10, 2):     if ...READ MORE

answered Feb 9, 2022 in Python by Nandini
• 5,480 points
2,123 views
0 votes
1 answer

Can someone explain the behaviour of increment and decrement operators in python

down voteaccepted ++ is not an operator. It is ...READ MORE

answered May 15, 2018 in Python by aryya
• 7,450 points
1,513 views
0 votes
1 answer

I want to download a file from the website by web scraping. Can anyone explain how to do this in jupyter lab (python) with an example?

Hey, Web scraping is a technique to automatically ...READ MORE

answered Apr 7, 2020 in Python by Gitika
• 65,910 points
2,107 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,070 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
3,491 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP