Quest
You are not signed in

Join Boardspeck to have access to amazing features

LOGIN
Card image cap
WHAT IS THE DIFFERENCE BETWEEN [ ] AND { ] IN PYTHON?
KABIRU SHUAIBU

Share this with friends

In Python, square brackets [] are used for lists, while curly braces {} are used for dictionaries.

A list is a collection of items that are ordered and changeable. You can access items from a list by their index, and you can add or remove items from a list. Here is an example of a list in Python:

my_list = ['apple', 'banana', 'orange'] 
 

A dictionary is a collection of items that are unordered and changeable. Each item in a dictionary consists of a key and a value, and you can access items from a dictionary by their keys. Here is an example of a dictionary in Python:

my_dict = { 
 'name': 'John Doe', 
 'age': 32, 
 'city': 'New York' 

 

Both lists and dictionaries are data types that are commonly used in Python, but they are used for different purposes. Lists are used to store a collection of items that are ordered and accessible by their index, while dictionaries are used to store a collection of items that are unordered and accessible by their keys.

Peer-to-Peer Review/Critique

What qualifies as a critique on Boardspeck

  • Your thoughts about this article
  • An analysis of this article
  • A commendation of this article
  • Your constructive criticism of this article
  • A recommedation for author's improvement

  • To send a review or critique to this Author on this article, Please LOGIN or SIGN UP

    Author


    Insightful data analyst with over three years of experience who is process-oriented. With extensive experience evaluating and analyzing data to generate development for technological and financial firms. Provide the insights, analytics, and business intelligence required to make decisions.

    Most Read Boardspeck Posts