-2

a=[12,23,34] a={12,23,34} I typed both of them in python 3.5 to see how it was different but couldn't understand it....

Here's my PowerShell

   PS C:\Users\CBB\Desktop> python

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> a={12,12,12}

>>> a
{12}

>>> a={12,23,34}

>>> a
{34, 12, 23}

>>> a=[12,23,45,67]

>>> a
[12, 23, 45, 67]
  • Possible duplicate of [What is the difference between sets and lists in Python?](https://stackoverflow.com/questions/12354515/what-is-the-difference-between-sets-and-lists-in-python) – iacob Aug 04 '18 at 11:44
  • Please read a basic tutorial, see e.g. https://sopython.com/wiki/What_tutorial_should_I_read%3F – jonrsharpe Aug 04 '18 at 12:02

1 Answers1

1

By a=[12,23,34], you define a list object.

By a={12,23,34}, a set object is created.

Lists are a part of the core Python language.8 Despite their name, Python’s lists are implemented as dynamic arrays behind the scenes. This means a list allows elements to be added or removed, and the list will automatically adjust the backing store that holds these elements by allocating or releasing memory. Python lists can hold arbitrary elements—“everything” is an object in Python, including functions. Therefore, you can mix and match different kinds of data types and store them all in a single list.

A set is an unordered collection of objects that does not allow duplicate elements. Typically, sets are used to quickly test a value for membership in the set, to insert or delete new values from a set, and to compute the union or intersection of two sets.

The above comment borrowed from Python Tricks of Dan Bader

BugKiller
  • 1,470
  • 1
  • 13
  • 22