Python Programming Fundamentals Lessons PDF
Document Details
Uploaded by AmazedEpigram1063
Tags
Related
- Python Game Coding Level 1 Learner Resource Lesson 3 PDF
- Python Programming Fundamentals PDF
- SDU University CSS 115: Python Programming Fundamentals Fall 2024 Lecture 4 PDF
- BSc (Hons) Electronics Ist Sem - Programming Fundamentals using Python PDF
- Python Programming Lesson 1 PDF
- Java SIBA Syllabus Lesson 01 MCQ - Programming Terminology PDF
Summary
This document is a set of Python programming lessons. The lessons cover a wide range of topics, from introduction to Python, basic programming constructs, data types, operators, functions, lists, dictionaries, file handling, and object-oriented programming (OOP). The document also includes practice programs for the concepts discussed.
Full Transcript
Python Lessons: Programming Fundamentals ======================================== Lesson 1: Basics of Python -------------------------- 1\. Introduction to Python\ - Python is an easy-to-learn, powerful programming language.\ - Used for web development, data analysis, AI, and automation. 2\. Inst...
Python Lessons: Programming Fundamentals ======================================== Lesson 1: Basics of Python -------------------------- 1\. Introduction to Python\ - Python is an easy-to-learn, powerful programming language.\ - Used for web development, data analysis, AI, and automation. 2\. Installing Python\ - Download from python.org.\ - Install an IDE like Visual Studio Code or use Jupyter Notebook. 3\. Hello World Program\ print(\"Hello, World!\") 4\. Key Features\ - Interpreted: Executes line by line.\ - Dynamic typing: No need to define variable types.\ - Rich libraries: Wide variety of built-in tools. Lesson 2: Variables and Data Types ---------------------------------- 1\. Variables\ - Variables store data.\ - Example:\ x = 5\ name = \"Alice\" 2\. Data Types\ - int: Integer numbers.\ - float: Decimal numbers.\ - str: Text.\ - bool: True/False.\ - Example:\ age = 25\ height = 5.9\ name = \"John\"\ is\_student = True Lesson 3: Operators ------------------- 1\. Arithmetic Operators\ - Addition (+), Subtraction (-), Multiplication (\*), Division (/), Modulus (%).\ - Example:\ x = 10\ y = 3\ print(x + y) \# 13\ print(x % y) \# 1 2\. Comparison Operators\ - Equal (==), Not equal (!=), Greater than (\>), Less than (\= 18:\ print(\"Adult\")\ else:\ print(\"Minor\")\ \ 2. Loops\ - for loop:\ for i in range(5):\ print(i)\ - while loop:\ count = 0\ while count \< 5:\ print(count)\ count += 1 Lesson 5: Functions ------------------- 1\. Defining Functions\ def greet(name):\ return f\"Hello, {name}!\"\ print(greet(\"Alice\"))\ \ 2. Parameters and Return\ - Functions accept inputs and return outputs.\ - Example:\ def add(a, b):\ return a + b\ print(add(3, 4)) Lesson 6: Lists and Loops ------------------------- 1\. Lists\ - Ordered collection of elements.\ - Example:\ fruits = \[\"apple\", \"banana\", \"cherry\"\]\ print(fruits\[1\]) \# banana\ \ 2. Iterating Over Lists\ for fruit in fruits:\ print(fruit) Lesson 7: Dictionaries ---------------------- 1\. Dictionaries\ - Key-value pairs.\ - Example:\ student = {\"name\": \"Alice\", \"age\": 20}\ print(student\[\"name\"\]) \# Alice Lesson 8: File Handling ----------------------- 1\. Read/Write Files\ \# Write to a file\ with open(\"example.txt\", \"w\") as file:\ file.write(\"Hello, World!\")\ \ \# Read from a file\ with open(\"example.txt\", \"r\") as file:\ print(file.read()) Lesson 9: Object-Oriented Programming (OOP) ------------------------------------------- 1\. Classes and Objects\ class Person:\ def \_\_init\_\_(self, name, age):\ self.name = name\ self.age = age\ \ def greet(self):\ return f\"Hi, I\'m {self.name}!\"\ \ john = Person(\"John\", 30)\ print(john.greet()) Lesson 10: Practice Programs ---------------------------- 1\. Simple Calculator\ def calculator(a, b, operation):\ if operation == \"add\":\ return a + b\ elif operation == \"subtract\":\ return a - b\ elif operation == \"multiply\":\ return a \* b\ elif operation == \"divide\":\ return a / b\ else:\ return \"Invalid operation\"\ \ print(calculator(10, 5, \"add\"))\ \ 2. FizzBuzz\ for i in range(1, 101):\ if i % 3 == 0 and i % 5 == 0:\ print(\"FizzBuzz\")\ elif i % 3 == 0:\ print(\"Fizz\")\ elif i % 5 == 0:\ print(\"Buzz\")\ else:\ print(i)