[go: up one dir, main page]

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

Lecture 5 (Datatypes overview)

This document provides an overview of Python data types, including numbers, strings, lists, tuples, and dictionaries. It explains the characteristics of each data type, such as mutability and how they are defined in Python. Additionally, it highlights Python's dynamic typing and the ability to handle large numbers and negative indices.

Uploaded by

loginoptions6
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)
0 views3 pages

Lecture 5 (Datatypes overview)

This document provides an overview of Python data types, including numbers, strings, lists, tuples, and dictionaries. It explains the characteristics of each data type, such as mutability and how they are defined in Python. Additionally, it highlights Python's dynamic typing and the ability to handle large numbers and negative indices.

Uploaded by

loginoptions6
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
You are on page 1/ 3

🧠 Python Datatypes (Lecture 5)

🎥 Reference

🟢 Introduction to Python Data Types

 Python is dynamically typed, meaning you don't need to declare the data type
of a variable.
 Data types determine the kind of operations that can be done on a value.
 Python supports multiple built-in data types.

🔢 Numbers

 Used to store numeric values.


 Types:
o int: Whole numbers (e.g. 5)
o float: Decimal numbers (e.g. 3.14)
o complex: Complex numbers (e.g. 2 + 3j)
 Python supports arbitrarily large integers.
 Supports exponentiation using ** operator:

print(2 ** 100)

🧵 Strings

 A sequence of characters enclosed in single (') or double (") quotes.


 Immutable — cannot be changed after creation.
 Support indexing, slicing, and negative indexing:
Code:

s = "Python"
print(s[0]) # 'P'
print(s[-1]) # 'n'

📃 Lists

 A collection of items, mutable, ordered, and can contain elements of different


types.
 Created using square brackets [].

Code:

my_list = [1, "hello", 3.5]


my_list[0] = 10 # You can modify items

🔐 Tuples

 Like lists, but immutable — once created, their elements can’t be changed.
 Use parentheses () to define:

Code:

my_tuple = (1, 2, "hi")

📖 Dictionaries

 Unordered collection of key-value pairs.


 Keys must be unique and immutable.
 Created using curly braces {}:

Code:

my_dict = {"name": "Hassan", "age": 18}


print(my_dict["name"]) # Output: Hassan

🧠 Bonus Concepts

 Python allows operations with large numbers, negative indices, and dynamic
typing.
 Lists, tuples, and dictionaries are core to storing structured data in Python.
 Strings and tuples are immutable; lists and dictionaries are mutable.

You might also like