0% found this document useful (0 votes)
2 views3 pages

Python Data Types Reference

The document provides a comprehensive overview of Python data types, including strings, integers, floats, booleans, lists, tuples, sets, and dictionaries. Each data type is defined with examples demonstrating their usage and key characteristics. The document serves as a full reference for understanding and utilizing these basic data types in Python programming.
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)
2 views3 pages

Python Data Types Reference

The document provides a comprehensive overview of Python data types, including strings, integers, floats, booleans, lists, tuples, sets, and dictionaries. Each data type is defined with examples demonstrating their usage and key characteristics. The document serves as a full reference for understanding and utilizing these basic data types in Python programming.
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
You are on page 1/ 3

Python Data Types - Full Reference

String (str)

Definition: Sequence of characters inside single or double quotes.


Example:
name = 'Hello World'
print(name[0]) # H
print(name[0:5]) # Hello
print(len(name)) # 11
print(name.upper()) # HELLO WORLD
print(name.replace('World', 'Python')) # Hello Python

Integer (int)

Definition: Whole numbers without decimals.


Example:
a = 10
b=3
print(a + b) # 13
print(a // b) # 3
print(a % b) # 1
print(abs(-5)) # 5

Float (float)

Definition: Numbers with decimals.


Example:
x = 5.75
y = 2.0
print(x / y) # 2.875
print(round(x)) # 6
print(round(3.14159, 2)) # 3.14

Boolean (bool)

Definition: Logical True or False values.


Example:
age = 20
print(age >= 18) # True
print(bool(0)) # False
print(bool('Hello')) # True

Page 1
Python Data Types - Full Reference

List (list)

Definition: Ordered, mutable collection.


Example:
fruits = ['apple', 'banana', 'cherry']
fruits.append('orange')
print(fruits)
fruits.remove('banana')
print(fruits)
fruits[0] = 'grape'
print(fruits)

Tuple (tuple)

Definition: Ordered, immutable collection.


Example:
colors = ('red', 'green', 'blue')
print(colors[1]) # green
print(len(colors)) # 3

Set (set)

Definition: Unordered collection with no duplicates.


Example:
nums = {1, 2, 3}
nums.add(4)
print(nums)
nums.update([3, 5, 6])
print(nums)
nums.remove(2)
print(nums)

Dictionary (dict)

Definition: Key-value pairs.


Example:
person = {'name': 'Ali', 'age': 30}
print(person['name'])
person['age'] = 31
person['city'] = 'Cairo'
print(person)

Page 2
Python Data Types - Full Reference

del person['city']
print(person)

Page 3

You might also like