[Go to site: main page, start]

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

Python Programming Study Notes

This document serves as a comprehensive guide for beginners to learn Python programming, covering essential topics such as variables, control flow, functions, and object-oriented programming. It also includes practical tips, useful libraries, and error handling techniques to help learners become job-ready. The content is structured in a way that promotes understanding and application of Python concepts.

Uploaded by

kucingilo1357
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)
20 views3 pages

Python Programming Study Notes

This document serves as a comprehensive guide for beginners to learn Python programming, covering essential topics such as variables, control flow, functions, and object-oriented programming. It also includes practical tips, useful libraries, and error handling techniques to help learners become job-ready. The content is structured in a way that promotes understanding and application of Python concepts.

Uploaded by

kucingilo1357
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

Python Programming

Complete Study Notes for Beginners


From Zero to Job-Ready in Python

Table of Contents
• 1. Introduction to Python

• 2. Variables & Data Types

• 3. Control Flow (If/Else, Loops)

• 4. Functions

• 5. Lists, Tuples & Dictionaries

• 6. Object-Oriented Programming (OOP)

• 7. File Handling

• 8. Error Handling
• 9. Useful Libraries

• 10. Tips & Tricks

1. Introduction to Python
Python is a high-level, interpreted, general-purpose programming language. It is widely used for web
development, data science, AI/ML, automation, and more.

Why Python?
✓ Simple and readable syntax

✓ Huge community and library ecosystem

✓ Cross-platform (Windows, Mac, Linux)

✓ Free and open source

✓ Used by Google, Netflix, NASA, and many more

Installing Python: Download from [Link] and install. Then use pip to install packages.
print("Hello, World!")

2. Variables & Data Types


Variables store data. Python is dynamically typed – you don't need to declare types.
# Integer age = 25
# Float price = 19.99
# String name = "Ahmad"
# Boolean is_active = True
# Check type print(type(age)) #
# Multiple assignment x, y, z = 1, 2, 3

3. Control Flow
Control flow determines the order your code executes.

If / Elif / Else:
score = 85 if score >= 90: print("A") elif score >= 80: print("B") else: print("C")

For Loop:
for i in range(5): print(i) # prints 0,1,2,3,4

While Loop:
count = 0 while count < 5: print(count) count += 1

4. Functions
Functions are reusable blocks of code. Use def keyword to define them.
def greet(name, greeting="Hello"): return f"{greeting}, {name}!"
print(greet("Siti")) # Hello, Siti! print(greet("Ali", "Hai")) # Hai, Ali!

■ Tip: Use default parameter values to make functions more flexible.

5. Lists, Tuples & Dictionaries


List (mutable, ordered):
fruits = ["apple", "mango", "durian"] [Link]("banana") print(fruits[0]) #
apple print(len(fruits)) # 4

Tuple (immutable, ordered):


coordinates = (3.1, 101.6) # lat, long of KL print(coordinates[0]) # 3.1

Dictionary (key-value pairs):


student = {"name": "Ahmad", "age": 20, "gpa": 3.8} print(student["name"]) # Ahmad
student["age"] = 21 # update value

6. OOP – Object-Oriented Programming


OOP organizes code using classes and objects.
class Animal: def __init__(self, name, sound): [Link] = name [Link] = sound
def speak(self): return f"{[Link]} says {[Link]}!" cat = Animal("Cat",
"Meow") print([Link]()) # Cat says Meow!

7. File Handling
# Write to file with open("[Link]", "w") as f: [Link]("Hello, File!") # Read
from file with open("[Link]", "r") as f: content = [Link]() print(content)

■ Always use 'with' statement – it automatically closes the file.

8. Error Handling
try: result = 10 / 0 except ZeroDivisionError: print("Cannot divide by zero!")
except Exception as e: print(f"Error: {e}") finally: print("This always runs")

9. Useful Libraries
Library Use Case

import pandas Data analysis and manipulation

import numpy Numerical computing and arrays


import matplotlib Data visualization and charts

import requests HTTP requests and web APIs

import flask Web development (lightweight)

import scikit-learn Machine learning algorithms

import selenium Web browser automation

import pillow Image processing and manipulation

10. Tips & Tricks


■ Use list comprehension: squares = [x**2 for x in range(10)]

■ f-strings for formatting: f'Hello {name}, you are {age} years old'

■ Unpack variables: first, *rest = [1, 2, 3, 4, 5]

■ Ternary operator: result = 'yes' if condition else 'no'

■ enumerate() for index + value: for i, v in enumerate(my_list):

■ zip() to pair lists: for a, b in zip(list1, list2):

■ Use virtual environments: python -m venv myenv

■ Practice daily on LeetCode, HackerRank, or Codewars!

Happy Coding! ■ | Keep learning. Keep building.

You might also like