Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Dictionaries

Python Tutorial

Introduction

Edit Template
  • Home
  • /
  • Python Dictionaries

Python Dictionaries

A dictionary in Python is an ordered collection used to store data in key-value pairs. It’s perfect when you need to label your data for clarity — just like fields in a form.

What is a Dictionary?

  • Each item in a dictionary is written as:

     
    key : value
  • Items are separated by commas.

  • The entire dictionary is enclosed in {}.

Example :
				
					student = {
    "name": "Hassan",
    "age": 20,
    "isEnrolled": True
}
print(student)


				
			

Output:

				
					{'name': 'Hassan', 'age': 20, 'isEnrolled': True}

				
			

Here:

  • "name" is a key and "Hassan" is its value.

  • "age" has the value 20.

  • "isEnrolled" has the boolean value True.

Key Features

  • Keys are unique.

  • Values can be of any data type — string, number, boolean, list, even another dictionary!

  • You can access, modify, add, or remove items easily.

Summary

  • Use {} to create a dictionary.

  • Store values as key-value pairs.

  • Great for structured data like a person’s profile, student records, or configurations.

Keep practicing — only on Learn With Arshyan.

Scroll to Top