CS105: Introduction to Python

About This Course

CS105: Introduction to Python – Your Ultimate Guide to Mastering Python in 2026

Welcome to CS105: Introduction to Python, your comprehensive guide to mastering one of the world’s most popular and versatile programming languages. Whether you are a complete beginner with no prior coding experience or an experienced programmer looking to add Python to your skillset, this course is designed to take you from zero to hero. [1]

In today’s rapidly evolving technological landscape, Python has become an essential skill for professionals across various industries, including web development, data science, machine learning, artificial intelligence, and automation. This course will provide you with a solid foundation in Python programming, enabling you to build robust applications and solve real-world problems.

Why Learn Python?

Python’s popularity stems from its simple and elegant syntax, which makes it easy to read and write. Its extensive standard library and a vast ecosystem of third-party packages provide ready-to-use solutions for a wide range of tasks, significantly speeding up the development process. [2]

Here are some of the key advantages of learning Python:

  • Beginner-Friendly: Python’s clean syntax and intuitive design make it an ideal language for beginners.
  • Versatile: From web development to data analysis, Python can be used for a wide variety of applications.
  • High Demand: Python is one of the most in-demand programming languages in the job market.
  • Large Community: Python has a massive and active community, which means you can easily find help and resources online.

Getting Started with Python

Before we dive into the world of Python programming, let’s get your development environment set up. The first step is to install Python on your computer. You can download the latest version of Python from the official website: https://www.python.org/downloads/.

Once you have installed Python, you will need a code editor or an Integrated Development Environment (IDE) to write and run your Python code. Some popular choices for Python development include:

  • Visual Studio Code: A lightweight and powerful code editor with excellent Python support.
  • PyCharm: A full-featured IDE specifically designed for Python development.
  • Jupyter Notebook: An interactive environment that is widely used for data science and scientific computing.

Python Basics: The Building Blocks of Programming

Now that you have your development environment set up, let’s start with the fundamentals of Python programming. In this section, we will cover the basic building blocks that you will use to write your Python programs.

Python Syntax and Comments

Python’s syntax is designed to be clean and readable. It uses indentation to define code blocks, which makes the code look neat and organized. Comments are an essential part of any program, as they help to explain the code and make it easier to understand. In Python, comments start with a hash symbol (#).

# This is a single-line comment
print("Hello, World!") # This is an inline comment

Variables and Data Types

Variables are used to store data in a program. In Python, you don’t need to declare the data type of a variable. The interpreter automatically determines the data type based on the value assigned to it. Python has several built-in data types, including:

  • Numbers: Integers, floating-point numbers, and complex numbers.
  • Strings: A sequence of characters enclosed in single or double quotes.
  • Booleans: Represents one of two values: True or False.
# Variable assignment
name = "Alice"
age = 30
pi = 3.14
is_student = True

Operators

Operators are used to perform operations on variables and values. Python supports a wide range of operators, including:

  • Arithmetic Operators: +, -, *, /, %, **, //
  • Comparison Operators: ==, !=, >, <, >=, <=
  • Logical Operators: and, or, not

Control Flow: Making Decisions in Your Code

Control flow statements allow you to control the order in which the statements in your program are executed. In this section, we will cover the most important control flow statements in Python.

Conditional Statements: if, elif, and else

Conditional statements are used to execute different blocks of code based on certain conditions. The if statement is used to execute a block of code if a condition is true. The elif statement is used to check for another condition if the previous condition was false. The else statement is used to execute a block of code if all the previous conditions were false.

# Conditional statements
x = 10
if x > 0:
    print("x is positive")
elif x < 0:
    print("x is negative")
else:
    print("x is zero")

Loops: for and while

Loops are used to execute a block of code repeatedly. The for loop is used to iterate over a sequence of elements, such as a list or a string. The while loop is used to execute a block of code as long as a condition is true.

# For loop
for i in range(5):
    print(i)

# While loop
i = 0
while i < 5:
    print(i)
    i += 1

Data Structures: Organizing Your Data

Data structures are used to store and organize data in a program. Python has several built-in data structures that are powerful and easy to use.

Lists

Lists are ordered and mutable collections of items. They can contain items of different data types.

# List
my_list = [1, "hello", 3.14, True]
print(my_list[0]) # Accessing elements
my_list[1] = "world" # Modifying elements
my_list.append(False) # Adding elements

Tuples

Tuples are ordered and immutable collections of items. Once a tuple is created, you cannot change its contents.

# Tuple
my_tuple = (1, "hello", 3.14, True)
print(my_tuple[0]) # Accessing elements

Dictionaries

Dictionaries are unordered collections of key-value pairs. They are used to store data in a way that is easy to look up.

# Dictionary
my_dict = {"name": "Alice", "age": 30}
print(my_dict["name"]) # Accessing elements
my_dict["city"] = "New York" # Adding elements

Functions: Reusing Your Code

Functions are blocks of code that can be reused throughout a program. They help to make the code more organized and easier to maintain.

# Function
def greet(name):
    print(f"Hello, {name}!")

greet("Alice")

Object-Oriented Programming (OOP)

Object-Oriented Programming (OOP) is a programming paradigm that is based on the concept of objects. Objects are instances of classes, which are blueprints for creating objects. OOP helps to create modular and reusable code.

# Class
class Dog:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def bark(self):
        print("Woof!")

# Object
my_dog = Dog("Buddy", 3)
my_dog.bark()

## Modules and Packages

Modules and packages are essential for organizing and reusing code in Python. A module is a file containing Python definitions and statements, while a package is a collection of modules.

### Using Modules

To use a module in your program, you need to import it using the `import` statement. For example, to use the `math` module, you would write:

```python
import math

print(math.pi)
print(math.sqrt(16))

Creating Your Own Modules

You can create your own modules by saving your Python code in a file with a .py extension. For example, you can create a file named my_module.py with the following content:

# my_module.py
def greet(name):
    print(f"Hello, {name}!")

Then, you can import and use this module in another Python file:

import my_module

my_module.greet("Alice")

File I/O

File I/O (Input/Output) is the process of reading from and writing to files. Python provides built-in functions to perform these operations.

Reading from a File

To read from a file, you first need to open it using the open() function. The open() function returns a file object, which has a read() method for reading the content of the file.

# Reading from a file
with open("my_file.txt", "r") as f:
    content = f.read()
    print(content)

Writing to a File

To write to a file, you need to open it in write mode ("w"). The write() method is used to write a string to the file.

# Writing to a file
with open("my_file.txt", "w") as f:
    f.write("Hello, World!\n")
    f.write("This is a new line.")

## Error and Exception Handling

Error and exception handling is a crucial aspect of writing robust and reliable Python code. It allows you to gracefully handle unexpected errors and prevent your program from crashing.

### Try and Except Blocks

The `try` and `except` blocks are used to handle exceptions in Python. The code that might raise an exception is placed inside the `try` block, and the code to handle the exception is placed inside the `except` block.

```python
# Try and except blocks
try:
    x = 1 / 0
except ZeroDivisionError:
    print("You cannot divide by zero!")

Handling Multiple Exceptions

You can handle multiple exceptions by specifying multiple except blocks.

# Handling multiple exceptions
try:
    x = int(input("Enter a number: "))
    y = 1 / x
except ValueError:
    print("Invalid input! Please enter a number.")
except ZeroDivisionError:
    print("You cannot divide by zero!")

Regular Expressions

Regular expressions (regex) are a powerful tool for working with strings. They allow you to search, match, and manipulate text based on patterns.

The re Module

Python provides the re module for working with regular expressions. The re.search() function is used to search for a pattern in a string.

import re

text = "The quick brown fox jumps over the lazy dog."
pattern = r"fox"

match = re.search(pattern, text)
if match:
    print("Pattern found!")

Debugging

Debugging is the process of finding and fixing errors in your code. Python provides a built-in debugger called pdb.

Using pdb

You can start the debugger by importing the pdb module and calling the pdb.set_trace() function at the point in your code where you want to start debugging.

import pdb

x = 10
y = 20

pdb.set_trace()

z = x + y
print(z)

Virtual Environments and PIP

Virtual environments are used to create isolated Python environments for your projects. This allows you to have different versions of packages for different projects.

Creating a Virtual Environment

You can create a virtual environment using the venv module.

python -m venv my_env

Activating a Virtual Environment

Once you have created a virtual environment, you need to activate it.

# On Windows
my_env\Scripts\activate

# On macOS and Linux
source my_env/bin/activate

Using PIP

PIP is the package installer for Python. You can use PIP to install, upgrade, and uninstall packages.

# Install a package
pip install requests

# Upgrade a package
pip install --upgrade requests

# Uninstall a package
pip uninstall requests

Web Scraping with Beautiful Soup

Web scraping is the process of extracting data from websites. Beautiful Soup is a Python library that makes it easy to scrape information from web pages.

Installing Beautiful Soup

You can install Beautiful Soup using PIP.

pip install beautifulsoup4

Scraping a Web Page

Here is an example of how to use Beautiful Soup to scrape the title of a web page.

import requests
from bs4 import BeautifulSoup

url = "https://www.python.org/"
response = requests.get(url)

soup = BeautifulSoup(response.text, "html.parser")
print(soup.title.string)

Interacting with APIs

APIs (Application Programming Interfaces) allow you to interact with other applications and services. The requests library is a popular choice for making HTTP requests to APIs.

Making a GET Request

Here is an example of how to make a GET request to the GitHub API to get information about a user.

import requests

username = "octocat"
url = f"https://api.github.com/users/{username}"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    print(f"Name: {data['name']}")
    print(f"Bio: {data['bio']}")
else:
    print("Failed to retrieve user information.")

Conclusion and Next Steps

Congratulations on completing CS105: Introduction to Python! You have learned the fundamentals of Python programming, from the basics of syntax and data types to advanced topics like object-oriented programming, web scraping, and interacting with APIs. You are now well-equipped to start building your own Python projects and solving real-world problems.

To continue your Python journey, we recommend exploring the following topics:

  • Web Development with Django or Flask: Build powerful web applications with these popular Python frameworks.
  • Data Science with NumPy, Pandas, and Matplotlib: Analyze and visualize data with these essential data science libraries.
  • Machine Learning with Scikit-learn and TensorFlow: Build intelligent systems with these powerful machine learning libraries.

The journey of learning a new programming language is both challenging and rewarding. By completing this course, you have taken a significant step towards becoming a proficient Python programmer. The skills you have acquired will open up a world of opportunities and empower you to create innovative solutions to complex problems. Remember that practice is key to mastery, so we encourage you to continue building projects and exploring the vast Python ecosystem. We wish you the best of luck in your Python programming journey!

Asynchronous Programming with asyncio

Asynchronous programming is a programming paradigm that allows a program to run multiple tasks concurrently. This is particularly useful for I/O-bound tasks, such as making network requests or reading from a database. Python’s asyncio module provides a framework for writing single-threaded concurrent code using coroutines, event loops, and futures.

Coroutines

Coroutines are special functions that can be paused and resumed. They are defined using the async def syntax.

import asyncio

async def main():
    print('Hello')
    await asyncio.sleep(1)
    print('World')

asyncio.run(main())

Event Loop

The event loop is the core of every asyncio application. It runs in a single thread and is responsible for scheduling and executing coroutines.

GUI Development with Tkinter

Tkinter is Python’s standard GUI (Graphical User Interface) library. It provides a powerful object-oriented interface to the Tk GUI toolkit.

Creating a Simple Window

Here is an example of how to create a simple window with a label and a button using Tkinter.

import tkinter as tk

window = tk.Tk()
window.title("My First GUI App")

label = tk.Label(window, text="Hello, World!")
label.pack()

button = tk.Button(window, text="Click Me!")
button.pack()

window.mainloop()

Embedded Video Tutorials

To further enhance your learning experience, we have embedded some of the best Python tutorials from YouTube. These videos will provide you with a visual and interactive way to learn Python.

Python Full Course for Beginners – Programming with Mosh

Python Full Course for Beginners – Dave Gray

Python Tutorial for Beginners – Telusko

Python for Everybody – Full Course – freeCodeCamp

References

[1] Python Software Foundation. (n.d.). Python For Beginners. Python.org. Retrieved January 20, 2026, from https://www.python.org/about/gettingstarted/

[2] W3Schools. (n.d.). Python Tutorial. Retrieved January 20, 2026, from https://www.w3schools.com/python/

Project Ideas to Solidify Your Skills

To truly master Python, it’s essential to apply your knowledge to real-world projects. Here are some project ideas to get you started:

  • Simple Calculator: Build a command-line calculator that can perform basic arithmetic operations.
  • To-Do List Application: Create a to-do list application that allows users to add, view, and delete tasks.
  • Web Scraper: Build a web scraper to extract data from your favorite website.
  • Guess the Number Game: Create a game where the computer randomly selects a number and the user has to guess it.
  • Contact Book: Build a contact book application that allows users to store and manage their contacts.

Learning Objectives

a:5:{i:0;s:47:"Gain a strong foundation in Python programming.";i:1;s:40:"Learn to write clean and efficient code.";i:2;s:51:"Develop practical skills through hands-on projects.";i:3;s:79:"Prepare for a career in software development, data science, or web development.";i:4;s:67:"Understand core programming concepts applicable to other languages.";}

Material Includes

  • Video lectures and demonstrations.
  • Downloadable code examples and exercises.
  • Quizzes and assignments to assess understanding.
  • Access to a course forum for questions and support.

Requirements

  • a:3:{i:0;s:41:"No prior programming experience required.";i:1;s:32:"A computer with internet access.";i:2;s:70:"Basic computer literacy (e.g., using a web browser, creating folders).";}

Target Audience

  • a:3:{i:0;s:47:"Beginners with no prior programming experience.";i:1;s:59:"Individuals interested in learning Python for data science.";i:2;s:61:"Students looking to explore a career in software development.";}
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare

Don't have an account yet? Sign up for free