Python – Dictionary

Click the link: “Python – Dictionary

In this tutorial we will learn about dictionary in Python.

We briefly talked about dictionary in the Python – Data Type tutorial.

What is a dictionary?

A dictionary is an unordered collection of key-value pairs.

We use curly { } brackets to create dictionary and separate key from value using : colon. Each pair of the dictionary is separated by , comma.

In the following example we are creating a dictionary of user data.

# dictionary
user = {
  "username": "yusufshakeel",
  "isOnline": False,
  "score": 9.1
}

# output
print("type:", type(user))
print(user)

We will get the following output.

type: <class 'dict'>
{'username': 'yusufshakeel', 'isOnline': False, 'score': 9.1}

 

Read more…

Advertisements

Python – Set Methods

Click the link: “Python – Set Methods

In this tutorial we will learn about set methods in Python.

In the previous tutorial Python – Set we learned about sets. Feel free to check that out.

Quick recap

  • A set is an unordered unique collection of items.
  • We create a set using curly { } brackets and separate the items using , comma.
  • Items of a set are not indexed.

Alright, let’s get started with set methods.

Read more…

Python – Set

Click the link: “Python – Set

In this tutorial we will learn about set in Python.

We briefly talked about set in the Python – Data Type tutorial.

What is a set?

A set is an unordered unique collection of items.

We create a set in Python using curly { } brackets and separate the items using , comma.

In the following example we are creating a set of integer values.

mySet = {1, 2, 3}

The set() constructor

We use the set() constructor to create a set in Python.

Read more…

Python – Tuple

Click the link: “Python – Tuple

In this tutorial we will learn about tuple in Python.

We briefly talked about tuple in the Python – Data Type tutorial.

What is a tuple?

Tuples are immutable ordered sequence of items similar to a List.

Once a tuple is created it can’t be changed.

To create a tuple in Python we use ( ) parenthesis and separate the items using , comma.

Items of a tuple are indexed and the first item gets the index 0.

In the following example we are creating a tuple of integer values.

myTuple = (1, 2, 3)

The tuple() constructor

We use the tuple() constructor to create a tuple in Python.

Read more…

Python – List Methods

Click the link: “Python – List Methods

In this tutorial we will learn about list methods in Python.

In the previous tutorial Python – List we learned about lists. Feel free to check that out.

Quick recap

  • A list is an ordered sequence of items.
  • We create lists in Python using the [ ].
  • Items inside the list are indexed.
  • Indexing starts from 0.

Alright, let’s get started with list methods.

Read more…

Python – List

Click the link: “Python – List

In this tutorial we will learn about list in Python.

We briefly talked about list in the Python – Data Type tutorial.

What is a list?

A list is an ordered sequence of items. We use square brackets [ ] to create a list in Python.

The items of a list are comma , separated and can be of multiple types like integer, floating point number, string, boolean, complex number.

A list can have an item repeated multiple times.

Read more…

Python – Math Module

Click the link: “Python – Math Module

In this tutorial we will learn about Math module and Mathematical Functions in Python.

Math Module

The math module is a standard module available in Python and it provides mathematical functions to developers.

To use the functions available in the math module we must start by first including the module using the import statement.

Write the following line to import the math module.

import math

Read more…