# Day 6 – Python Variables and Data Types

![](https://cdn.hashnode.com/uploads/covers/664f77938fc1f806b829b90b/c3fb105b-69c9-4171-9059-bd8d8f7555c5.jpg align="center")

Welcome to **Day 6 of 100 Days of Python!**

Today, we are learning two of the most fundamental concepts in programming:

*   Variables
    
*   Data Types
    

Whenever we write a Python program, we work with different kinds of values such as numbers, text, `True`/`False`, collections, and more. Variables give these values names, while data types tell Python what kind of values they are.

* * *

# 1\. What is a Variable?

A **variable** is a name that refers to a value or object in a Python program.

You can think of a variable as a label attached to some data.

For example:

```python
a = 1
b = True
c = "Sritesh"
d = None
```

Here:

*   `a` refers to the integer `1`
    
*   `b` refers to the Boolean value `True`
    
*   `c` refers to the string `"Sritesh"`
    
*   `d` refers to `None`
    

Python variables do not need their data type to be declared explicitly.

For example:

```python
age = 23
name = "Sritesh"
height = 5.5
```

Python automatically determines the type of each value.

* * *

# 2\. Creating Variables

Creating a variable in Python is simple.

The general syntax is:

```python
variable_name = value
```

Example:

```python
name = "Sritesh"
age = 23
is_learning = True
```

The `=` symbol is called the **assignment operator**.

It assigns the value on the right to the variable name on the left.

For example:

```python
age = 23
```

means that `age` now refers to the value `23`.

* * *

# 3\. What is a Data Type?

A **data type** describes the kind of value an object represents.

Different types of data support different operations.

For example:

```python
a = 10
b = 20

print(a + b)
```

Output:

```text
30
```

Here, `a` and `b` are integers, so addition performs numerical addition.

Now consider:

```python
a = "10"
b = "20"

print(a + b)
```

Output:

```text
1020
```

Here, `a` and `b` are strings, so `+` joins the strings together.

This is why understanding data types is important.

* * *

# 4\. Checking the Type of a Value

Python provides the built-in `type()` function to check the type of an object.

Example:

```python
a = 10
print(type(a))
```

Output:

```text
<class 'int'>
```

Another example:

```python
name = "Sritesh"
print(type(name))
```

Output:

```text
<class 'str'>
```

The `type()` function is extremely useful while learning Python and debugging programs.

* * *

# 5\. Common Built-in Data Types

Python provides several built-in data types.

Some important ones are:

| Category | Data Types |
| --- | --- |
| Numeric | `int`, `float`, `complex` |
| Text | `str` |
| Boolean | `bool` |
| Sequence | `list`, `tuple`, `range` |
| Mapping | `dict` |
| Set | `set`, `frozenset` |
| Binary | `bytes`, `bytearray`, `memoryview` |
| None | `NoneType` |

In this lesson, we will focus on the types introduced in this day's program.

* * *

# 6\. Numeric Data Types

Python has three built-in numeric types:

*   `int`
    
*   `float`
    
*   `complex`
    

## `int`

`int` represents whole numbers.

Examples:

```python
a = 10
b = -8
c = 0
```

These are all integers.

You can perform mathematical operations on integers:

```python
a = 10
b = 5

print(a + b)
print(a - b)
print(a * b)
```

* * *

## `float`

`float` represents numbers containing a decimal point.

Examples:

```python
a = 7.349
b = -9.0
c = 0.0000001
```

You can check its type:

```python
a = 7.5
print(type(a))
```

Output:

```text
<class 'float'>
```

* * *

## `complex`

Python also supports complex numbers.

A complex number contains:

*   A real part
    
*   An imaginary part
    

Python uses `j` to represent the imaginary part.

For example:

```python
a = 1 + 2j
```

or:

```python
a = complex(1, 2)
```

Both represent the same complex number.

```python
print(a)
```

Output:

```text
(1+2j)
```

> **Note:** In Python, use `j`, not `i`, for the imaginary part.

* * *

# 7\. Text Data – `str`

The `str` type is used to represent text.

Strings can be written using single or double quotes.

```python
name = "Sritesh"
language = 'Python'
```

You can also store sentences:

```python
message = "I am learning Python."
```

Check the type:

```python
print(type(message))
```

Output:

```text
<class 'str'>
```

* * *

# 8\. Boolean Data Type – `bool`

The Boolean data type has only two possible values:

```python
True
False
```

Example:

```python
is_learning = True
is_sleeping = False
```

Booleans are commonly used when making decisions in programs.

For example:

```python
age = 23
can_vote = age >= 18

print(can_vote)
```

Output:

```text
True
```

> Remember: `True` and `False` must begin with a capital letter.

* * *

# 9\. `NoneType` – `None`

Python has a special value called `None`.

It represents the **absence of a value** or a value that is currently not available.

Example:

```python
result = None

print(result)
print(type(result))
```

Output:

```text
None
<class 'NoneType'>
```

`None` is different from:

*   `0`
    
*   `False`
    
*   `""`
    

It specifically represents the absence of a value.

* * *

# 10\. Sequence Data Types

Python provides several sequence types.

In this lesson, we will look at:

*   `list`
    
*   `tuple`
    

* * *

## List

A **list** is an ordered, mutable collection of items.

Lists are written using square brackets `[]`.

Example:

```python
list1 = [8, 2.3, [-4, 5], ["apple", "banana"]]

print(list1)
```

Output:

```text
[8, 2.3, [-4, 5], ['apple', 'banana']]
```

A list can contain different types of values, including other lists.

For example:

```python
numbers = [10, 20, 30]
names = ["Sritesh", "Python"]
mixed = [10, "Python", True, 5.5]
```

Lists are **mutable**, which means their contents can be changed after creation.

For example:

```python
numbers = [10, 20, 30]

numbers[0] = 100

print(numbers)
```

Output:

```text
[100, 20, 30]
```

We will explore lists in much more detail in a later day.

* * *

# 11\. Tuple

A **tuple** is an ordered, immutable collection of items.

Tuples are commonly written using parentheses `()`.

Example:

```python
tuple1 = (("parrot", "sparrow"), ("Lion", "Tiger"))

print(tuple1)
```

Output:

```text
(('parrot', 'sparrow'), ('Lion', 'Tiger'))
```

Unlike lists, tuples are **immutable**.

That means their existing elements cannot be changed after the tuple is created.

Example:

```python
numbers = (10, 20, 30)
```

You cannot directly change one of its elements like you can with a list.

We will learn more about tuples later.

* * *

# 12\. Dictionary – `dict`

A **dictionary** stores data as **key-value pairs**.

Dictionaries are written using curly brackets `{}`.

Example:

```python
student = {
    "name": "Sakshi",
    "age": 20,
    "canVote": True
}

print(student)
```

Output:

```text
{'name': 'Sakshi', 'age': 20, 'canVote': True}
```

Here:

*   `"name"` is a key and `"Sakshi"` is its value
    
*   `"age"` is a key and `20` is its value
    
*   `"canVote"` is a key and `True` is its value
    

A dictionary allows us to store related information using meaningful keys.

For example:

```python
person = {
    "name": "Sritesh",
    "age": 23,
    "language": "Python"
}
```

We can later access values using their keys.

```python
print(person["name"])
```

Output:

```text
Sritesh
```

Modern Python dictionaries preserve **insertion order**, meaning items generally appear in the order they were added. The important concept here is that dictionaries are **mappings of keys to values**, rather than sequences indexed by position.

* * *

# 13\. Checking Data Types

Let's check the types of the different values used in this lesson:

```python
a = complex(1, 2)
b = True
c = "Sritesh"
d = None

print(type(a))
print(type(b))
print(type(c))
print(type(d))
```

Output:

```text
<class 'complex'>
<class 'bool'>
<class 'str'>
<class 'NoneType'>
```

We can also check collections:

```python
list1 = [1, 2, 3]
tuple1 = (1, 2, 3)
dict1 = {"name": "Sritesh"}

print(type(list1))
print(type(tuple1))
print(type(dict1))
```

Output:

```text
<class 'list'>
<class 'tuple'>
<class 'dict'>
```

* * *

# 14\. Putting Everything Together

Here is the complete program from today's lesson:

```python
# Integer and float examples
# a = 123
# a = 1.23

# Complex number
a = complex(1, 2)

# Boolean
b = True

# String
c = "Sritesh"

# None
d = None

print(a)

a1 = 9
print(a + a1)

print("The type of a is", type(a))
print("The type of b is", type(b))
print("The type of c is", type(c))
print("The type of d is", type(d))

# List
list1 = [8, 2.3, [-4, 5], ["apple", "banana"]]

print(list1)
print("The type of list1 is", type(list1))

# Tuple
tuple1 = (("parrot", "sparrow"), ("Lion", "Tiger"))

print(tuple1)
print("The type of tuple1 is", type(tuple1))

# Dictionary
dict1 = {
    "name": "Sakshi",
    "age": 20,
    "canVote": True
}

print(dict1)
print("The type of dict1 is", type(dict1))
```

* * *

# 15\. Quick Revision

### Variable

A name that refers to a value or object.

```python
age = 23
```

### `int`

Whole numbers.

```python
age = 23
```

### `float`

Decimal numbers.

```python
height = 5.5
```

### `complex`

Complex numbers.

```python
number = 1 + 2j
```

### `str`

Text.

```python
name = "Sritesh"
```

### `bool`

`True` or `False`.

```python
is_learning = True
```

### `None`

Represents the absence of a value.

```python
result = None
```

### `list`

Ordered and mutable collection.

```python
numbers = [1, 2, 3]
```

### `tuple`

Ordered and immutable collection.

```python
numbers = (1, 2, 3)
```

### `dict`

Key-value mapping.

```python
student = {"name": "Sritesh", "age": 23}
```

* * *

# 16\. Key Takeaways

After completing Day 6, you should understand:

*   What a variable is
    
*   How to create and assign variables
    
*   What data types are
    
*   How to use the `type()` function
    
*   `int`, `float`, and `complex`
    
*   `str` for text
    
*   `bool` for Boolean values
    
*   `None` and `NoneType`
    
*   Lists and their mutability
    
*   Tuples and their immutability
    
*   Dictionaries and key-value pairs
    
*   Why understanding data types is important when writing Python programs
    

These concepts are the foundation for the next stages of Python. Once we understand how Python represents and stores different kinds of data, we can start performing operations on that data and building more useful programs.

* * *

## **📂 Day 6 Resources**

All notes and code for this day are available in the GitHub repository:

%[https://github.com/SriteshSuranjan/100-Days-of-Python/tree/main/06-Day06-Variables-and-Datatypes] 

* * *
