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]


a[2]= 200


print (a)

print (b)


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

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
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,440 points
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,950 points
0 votes
1 answer

what is the use of // operator in Python? Can anyone explain?

Hi, @Roshni, It is a Floor Divisionoperator, which ...READ MORE

answered Jun 23, 2020 in Python by Gitika
• 65,950 points
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 2,421 views
0 votes
0 answers
+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,810 points