0% found this document useful (0 votes)
2 views

Python Data Types Guide

This document serves as a beginner's guide to Python data types, outlining various built-in types including numeric, sequence, text, set, mapping, boolean, binary, and none types. It provides detailed explanations and examples for the integer data type, including memory consumption and use cases. Understanding these data types is essential for writing efficient and error-free Python programs.

Uploaded by

Anuradha Dhavala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Python Data Types Guide

This document serves as a beginner's guide to Python data types, outlining various built-in types including numeric, sequence, text, set, mapping, boolean, binary, and none types. It provides detailed explanations and examples for the integer data type, including memory consumption and use cases. Understanding these data types is essential for writing efficient and error-free Python programs.

Uploaded by

Anuradha Dhavala
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Data Types - Beginner's Guide

## 1. Introduction

Python has various **data types** that define the kind of values that variables can hold.

Understanding data types is crucial for writing efficient and error-free programs.

## 2. Fundamental Data Types in Python

Python has the following **built-in** data types:

- Numeric Types: `int`, `float`, `complex`

- Sequence Types: `list`, `tuple`, `range`

- Text Type: `str`

- Set Types: `set`, `frozenset`

- Mapping Type: `dict`

- Boolean Type: `bool`

- Binary Types: `bytes`, `bytearray`, `memoryview`

- None Type: `NoneType`

### 2.1 Integer (`int`)

- Stores whole numbers (positive, negative, or zero).

- Memory consumption: **28 bytes** (base size, increases dynamically as number size increases).

#### Example Usage:

```python

num1 = 100 # Positive integer

num2 = -25 # Negative integer


num3 = 0 # Zero

print(type(num1)) # Output: <class 'int'>

```

#### Additional Examples:

```python

# Performing arithmetic operations

sum_value = 5 + 10 # Addition

product = 5 * 3 # Multiplication

power = 2 ** 3 # Exponentiation

print(sum_value, product, power)

```

#### Memory Consumption Example:

```python

import sys

x = 10 # Small integer

y = 1000000000000000000 # Large integer

print(sys.getsizeof(x)) # Output: 28 bytes

print(sys.getsizeof(y)) # Output: More than 28 bytes, grows dynamically

```

#### Use Case:

- Counting items

- Representing IDs

- Performing arithmetic operations


... (Other data types are also included similarly)

You might also like