0% found this document useful (0 votes)
5 views22 pages

Python Data Types

The document provides a quick guide to Python data types, explaining that Python is dynamically typed and does not require explicit type declaration. It details built-in data types including numeric (int, float, complex), sequence (list, tuple, range), text (str), set (set, frozenset), mapping (dict), boolean (bool), and binary types (bytes, bytearray, memoryview). Additionally, it covers type checking and conversion methods.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views22 pages

Python Data Types

The document provides a quick guide to Python data types, explaining that Python is dynamically typed and does not require explicit type declaration. It details built-in data types including numeric (int, float, complex), sequence (list, tuple, range), text (str), set (set, frozenset), mapping (dict), boolean (bool), and binary types (bytes, bytearray, memoryview). Additionally, it covers type checking and conversion methods.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is dynamically typed,
meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.


• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is dynamically typed,
meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j
2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True
2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str
Category Data Types

Set set, frozenset

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is dynamically typed,
meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)
2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)
Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is dynamically typed,
meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types


Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type


• dict → Key-value pairs
Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)
5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset

Mapping dict

Boolean bool

bytes, bytearray,
Binary
memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is
dynamically typed, meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:
Category Data Types

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types


Category Data Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset


Category Data Types

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is
dynamically typed, meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)
Category Data Types

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:


Category Data Types

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is
dynamically typed, meaning you don’t need to declare the data type explicitly.
Category Data Types

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:
Category Data Types

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
Category Data Types

str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

Python Data Types – Quick Guide

1. Introduction

In Python, data types define the type of value a variable can hold. Python is
dynamically typed, meaning you don’t need to declare the data type explicitly.

2. Built-in Data Types

2.1 Numeric Types

Used for storing numbers.

• int → Integer values


Example: 10, -5, 1000

• float → Decimal numbers


Example: 10.5, -3.14
Category Data Types

• complex → Complex numbers


Example: 3 + 4j

2.2 Sequence Types

Used to store collections of items.

• list → Ordered, mutable collection


Example:

my_list = [1, 2, 3]

• tuple → Ordered, immutable collection


Example:

my_tuple = (1, 2, 3)

• range → Sequence of numbers


Example:

range(5)

2.3 Text Type

• str → String (text data)


Example:

name = "Python"

2.4 Set Types

Unordered collection of unique elements.

• set
Example:

my_set = {1, 2, 3}

• frozenset (immutable set)

2.5 Mapping Type

• dict → Key-value pairs


Example:

my_dict = {"name": "John", "age": 25}


Category Data Types

2.6 Boolean Type

• bool → Represents True or False


Example:

is_valid = True

2.7 Binary Types

• bytes

• bytearray

• memoryview

Example:

x = b"hello"

3. Type Checking

You can check the data type using:

type(variable)

Example:

x = 10
print(type(x)) # <class 'int'>

4. Type Conversion

Convert between types using:

int()
float()
str()
list()
tuple()
set()

Example:

x = "10"
y = int(x)

5. Summary Table
Category Data Types

Category Data Types

Numeric int, float, complex

Sequence list, tuple, range

Text str

Set set, frozenset

Mapping dict

Boolean bool

Binary bytes, bytearray, memoryview

You might also like