0% found this document useful (0 votes)
4 views2 pages

Python Data Types Guide

This document serves as a beginner's guide to Python data types, covering numeric types (int, float, complex), sequence types (str, list, tuple, range), set types (set, frozenset), mapping type (dict), boolean type (bool), binary types (bytes, bytearray, memoryview), and None type (NoneType). Each type is explained with definitions and usage examples to illustrate their application in Python programming. Additionally, it includes tips for beginners on how to use these data types effectively.

Uploaded by

subhan.a.b.h.c
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Python Data Types Guide

This document serves as a beginner's guide to Python data types, covering numeric types (int, float, complex), sequence types (str, list, tuple, range), set types (set, frozenset), mapping type (dict), boolean type (bool), binary types (bytes, bytearray, memoryview), and None type (NoneType). Each type is explained with definitions and usage examples to illustrate their application in Python programming. Additionally, it includes tips for beginners on how to use these data types effectively.

Uploaded by

subhan.a.b.h.c
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Data Types Guide for Beginners

1. Numeric Types
 int: Whole numbers. Example: 5, -10.
 float: Decimal numbers. Example: 3.14, -0.001.
 complex: Numbers with real and imaginary parts. Example: 2 + 3j.
Usage Examples:
# int
a = 10
# float
b = 3.14
# complex
z = 2 + 3j
print([Link], [Link])

2. Sequence Types
 str: Text. Example: 'Subhan'.
 list: Mutable collection. Example: [1, 2, 3].
 tuple: Immutable collection. Example: (1, 2, 3).
 range: Sequence of numbers. Example: range(5).
Usage Examples:
name = "Subhan"
fruits = ["apple", "banana"]
colors = ("red", "green")
for i in range(5):
print(i)

3. Set Types
 set: Mutable collection of unique elements. Example: {1, 2, 3}.
 frozenset: Immutable set. Example: frozenset({1, 2, 3}).
Usage Examples:
numbers = {1, 2, 3}
[Link](4)
fs = frozenset([1,2,3])
4. Mapping Type
 dict: Key-value pairs. Example: {'name': 'Subhan', 'age': 18}.
Usage Examples:
person = {"name": "Subhan", "age": 18}
print(person["name"])

5. Boolean Type
 bool: True or False.
Usage Examples:
a = 10
b = 5
print(a > b) # True

6. Binary Types
 bytes: Immutable bytes. Example: b'hello'.
 bytearray: Mutable bytes. Example: bytearray(b'hello').
 memoryview: Access binary data efficiently.
Usage Examples:
b = b"hello"
ba = bytearray(b"hello")
mv = memoryview(b"hello")

7. None Type
 NoneType: Represents no value. Example: None.
Usage Examples:
x = None
if x is None:
print("No value assigned")

Tips for Beginners: - Use parentheses () for range() and square


brackets [] for lists. - Strings require quotes " or '. - Tuples are
immutable, so you cannot change elements. - Sets remove duplicates
automatically. - Dictionaries store key-value pairs for fast lookup.

You might also like