Docsity

Advanced Python Programming & Fundamental Data Structures Course Notes, Lecture notes of Programming Languages

Toggle sidebar
bg1
COURSE: Computer Science / Information Technology 102
SUBJECT: Advanced Python Programming and Fundamental Data Structures
DOCUMENT TYPE: Full Semester Comprehensive Lecture Notes
AUTHOR: Carlwyn Melgarejo
CHAPTER 1: INTRODUCTORY PYTHON CONCEPTS
Python is a high-level, interpreted, and object-oriented programming
language known for its readability and dynamic semantics.
1. Variables and Data Types
In Python, variables do not require explicit declaration to reserve memory
space. The declaration happens automatically when you assign a value to a
variable.
Integer (int): Whole numbers without a fractional part. (e.g., age =
18)
Float (float): Numbers containing one or more decimals. (e.g., gpa =
3.75)
String (str): A sequence of characters enclosed in quotes. (e.g., name
= "Carlwyn")
Boolean (bool): Represents logic levels: True or False.
2. Control Flow Structures
Control flow is the order in which individual statements or instructions are
executed.
Conditional Statements (if-elif-else): Used for decision-making
operations.
python
score = 85
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
else:
print("Grade: C")
Use code with caution.
Looping Mechanisms (For and While): Used to iterate over a
sequence repeatedly.
python
pf3
pf4

Partial preview of the text

Download Advanced Python Programming & Fundamental Data Structures Course Notes and more Lecture notes Programming Languages in PDF only on Docsity!

COURSE: Computer Science / Information Technology 102

SUBJECT: Advanced Python Programming and Fundamental Data Structures

DOCUMENT TYPE: Full Semester Comprehensive Lecture Notes

AUTHOR: Carlwyn Melgarejo

CHAPTER 1: INTRODUCTORY PYTHON CONCEPTS

Python is a high-level, interpreted, and object-oriented programming

language known for its readability and dynamic semantics.

1. Variables and Data Types

In Python, variables do not require explicit declaration to reserve memory

space. The declaration happens automatically when you assign a value to a

variable.

 Integer (int): Whole numbers without a fractional part. (e.g., age =

 Float (float): Numbers containing one or more decimals. (e.g., gpa =

 String (str): A sequence of characters enclosed in quotes. (e.g., name

= "Carlwyn")

 Boolean (bool): Represents logic levels: True or False.

2. Control Flow Structures

Control flow is the order in which individual statements or instructions are

executed.

 Conditional Statements (if-elif-else): Used for decision-making

operations.

python

score = 85 if score >= 90 : print("Grade: A") elif score >= 80 : print("Grade: B") else: print("Grade: C") Use code with caution.

 Looping Mechanisms (For and While): Used to iterate over a

sequence repeatedly.

 python

 # For loop iterating through a range  for i in range( 1 , 4 ):  print(f"Iteration number: {i}")  Use code with caution. 

 CHAPTER 2: ADVANCED PYTHON DATA STRUCTURES

 Data structures allow us to organize and store data efficiently in a

computer's memory. Python has four built-in collection data types.

 1. Lists (Mutable and Ordered)

 A list allows duplicate elements and its items can be changed after

creation.

 python

 fruits = ["apple", "banana", "cherry"]  fruits.append("orange") # Adding an element  print(fruits) # Output: ['apple', 'banana', 'cherry', 'orange']  Use code with caution.

 2. Tuples (Immutable and Ordered)

 A tuple cannot be changed or modified after its creation. It is used to

protect data integrity.

 python

 coordinates = (14.55, 121.05) # Latitude and Longitude  # coordinates[0] = 15.00 <- This will throw a TypeError  Use code with caution.

 3. Dictionaries (Key-Value Pairs)

 Dictionaries store data values in key:value pairs. They are ordered and

mutable, but do not allow duplicate keys.

 python

 student_profile = {  "name": "Carlwyn",  "course": "Computer Science",  "year": 1  }  print(student_profile["course"]) # Output: Computer Science  Use code with caution.

Sets (Unordered and Unindexed)

4. Sets do not allow duplicate values. They are highly efficient for

mathematical operations like unions and intersections.

python

unique_ids = { 101 , 102 , 103 , 101 }

top). A Queue uses FIFO (First-In, First-Out), where items enter through

the rear (enqueue) and exit through the front (dequeue).