Can assignment operator be used to copy elements in Python

+1 vote
I have a dictionary in Python. I want to initialize them first and then copy elements from one to another. How to do it?
Jul 29, 2019 in Python by Arvind
• 3,040 points
587 views

1 answer to this question.

0 votes
Yes assignment operator can be used to copy elements from one dictionary to other. Also you can use copy() to do the same. Have a look at the following
>>> a,b = {},{} # initialize the dictionaries 
>>> a = {1:"hi",2:"hello"}
>>> a
{1: 'hi', 2: 'hello'}
>>> b=a # use of assignment operator
>>> b
{1: 'hi', 2: 'hello'}
>>> c=b.copy() # use of copy method
>>> c
{1: 'hi', 2: 'hello'}
>>> 

answered Jul 29, 2019 by Neel
• 3,020 points

edited Jul 30, 2019 by Neel

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Adding elements to a list in python

Use extend() instead: l = [5, 7, 12, ...READ MORE

answered Apr 23, 2018 in Python by Nietzsche's daemon
• 4,260 points
534 views
0 votes
1 answer

Which IDE can be used for Python on Mac OS X

Have tried many different (Kate, Eclipse, Scite, ...READ MORE

answered Oct 15, 2018 in Python by SDeb
• 13,300 points
1,094 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
0 votes
1 answer

How to add elements to a list in Python?

To initialize an empty list do this: new_list ...READ MORE

answered Jul 23, 2019 in Python by Neel
• 3,020 points
512 views
0 votes
1 answer

Is it possible to run a function in Python using the command line?

Suppose your file name is demo.py and ...READ MORE

answered Jun 26, 2019 in Python by Neel
• 3,020 points
742 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