Python Fundamentals: My Learning Journey¶

Author: Mohammad Sayem Chowdhury

Welcome! In this notebook, I'll share my personal approach to understanding Python's basic concepts. This covers the foundation I needed to start reading and writing Python code effectively. By the end, you'll see how I think about Python's basic types, expressions, and variables.

What I'll Cover¶

  • Saying "Hello" to Python
  • Understanding Python's Version
  • Writing Comments
  • Handling Errors
  • Basic Data Types (Integers, Floats, Booleans)
  • Expressions and Variables

Estimated time: about 25 minutes of hands-on exploration.


My First Python Program¶

Every programming journey starts with "Hello World" - it's like a handshake with the language. Here's my first Python code:

In [ ]:
# My first Python output
print('Hello, Python!')

The print() function is my go-to for displaying output. I passed the string 'Hello, Python!' as an argument to tell Python what to show.

Checking My Python Version¶

I always like to know which version of Python I'm using. Since Python 3 is the current standard, that's what I focus on:

In [ ]:
# Checking my Python version
import sys
print(sys.version)

The sys module gives me access to system-specific information, including the Python version.

Writing Comments: My Documentation Style¶

Comments are crucial for my coding practice. They help me remember what I was thinking and help others understand my code:

In [ ]:
# This is how I write comments in Python
print('Hello, Python!')  # This line displays a greeting
# print('This line is commented out')

I use the # symbol for comments. Everything after # on a line is ignored by Python. I also use comments to temporarily disable code without deleting it.

Understanding Errors: Learning from Mistakes¶

Making mistakes is part of learning. Python gives helpful error messages that guide me toward solutions:

In [ ]:
# Intentional error to see what happens
# frint("Hello, Python!")  # Uncomment to see the NameError

When I misspell print as frint, Python shows a NameError because it doesn't recognize frint as a function.

Python Data Types: My Building Blocks¶

Understanding data types is fundamental to how I work with information in Python.

Integers: Working with Whole Numbers¶

Integers are my go-to for counting and indexing:

In [ ]:
# Working with integers
my_age = 25
year = 2024
count = 100

print(f"My age: {my_age}")
print(f"Current year: {year}")
print(f"Item count: {count}")

# Checking the type
print(f"Type of my_age: {type(my_age)}")

Floats: Decimal Numbers in My World¶

For precise calculations involving decimals, I use floats:

In [ ]:
# Working with floats
pi = 3.14159
temperature = 98.6
price = 19.99

print(f"Pi: {pi}")
print(f"Body temperature: {temperature}°F")
print(f"Price: ${price}")

# Checking the type
print(f"Type of pi: {type(pi)}")

Type Conversion: Changing Between Types¶

Sometimes I need to convert between different data types:

In [ ]:
# Converting between types
original_number = 25
float_version = float(original_number)
string_version = str(original_number)

print(f"Original: {original_number} (type: {type(original_number)})")
print(f"As float: {float_version} (type: {type(float_version)})")
print(f"As string: {string_version} (type: {type(string_version)})")

# Converting back
back_to_int = int(float_version)
print(f"Back to int: {back_to_int} (type: {type(back_to_int)})")

Boolean Values: True or False Logic¶

Booleans are essential for decision-making in my code:

In [ ]:
# Working with booleans
is_student = True
is_graduated = False
likes_python = True

print(f"Am I a student? {is_student}")
print(f"Have I graduated? {is_graduated}")
print(f"Do I like Python? {likes_python}")

# Boolean operations
print(f"Type of is_student: {type(is_student)}")
print(f"Logical AND: {is_student and likes_python}")
print(f"Logical OR: {is_graduated or likes_python}")

Expressions: Building Calculations¶

Expressions are how I combine values and operators to create new values:

In [ ]:
# Basic arithmetic expressions
a = 10
b = 3

print(f"Addition: {a} + {b} = {a + b}")
print(f"Subtraction: {a} - {b} = {a - b}")
print(f"Multiplication: {a} * {b} = {a * b}")
print(f"Division: {a} / {b} = {a / b}")
print(f"Floor division: {a} // {b} = {a // b}")
print(f"Modulo: {a} % {b} = {a % b}")
print(f"Exponentiation: {a} ** {b} = {a ** b}")

Order of Operations¶

Just like in math, Python follows order of operations (PEMDAS):

In [ ]:
# Demonstrating order of operations
result1 = 2 + 3 * 4
result2 = (2 + 3) * 4
result3 = 2 ** 3 + 1

print(f"2 + 3 * 4 = {result1}")  # Multiplication first
print(f"(2 + 3) * 4 = {result2}")  # Parentheses first
print(f"2 ** 3 + 1 = {result3}")  # Exponentiation first

Variables: Storing My Data¶

Variables are like labeled containers where I store information:

In [ ]:
# Creating and using variables
name = "Mohammad Sayem Chowdhury"
favorite_number = 7
height_cm = 175.5
is_programmer = True

print(f"Name: {name}")
print(f"Favorite number: {favorite_number}")
print(f"Height: {height_cm} cm")
print(f"Is programmer: {is_programmer}")

Variable Naming: My Best Practices¶

I follow these rules when naming variables:

  • Use descriptive names
  • Start with a letter or underscore
  • Use lowercase with underscores for multiple words
  • Avoid Python keywords
In [ ]:
# Good variable naming examples
user_age = 25
total_cost = 99.99
is_valid_email = True
first_name = "Mohammad"

# Demonstrating variable reassignment
counter = 0
print(f"Initial counter: {counter}")

counter = counter + 1
print(f"After increment: {counter}")

counter += 5  # Shorthand for counter = counter + 5
print(f"After adding 5: {counter}")

Practice Exercises: Testing My Understanding¶

Let me work through some exercises to reinforce these concepts:

In [ ]:
# Exercise 1: Calculate the area of a rectangle
length = 10.5
width = 7.2
area = length * width

print(f"Rectangle dimensions: {length} x {width}")
print(f"Area: {area} square units")
print(f"Area type: {type(area)}")
In [ ]:
# Exercise 2: Convert temperature from Celsius to Fahrenheit
celsius = 25
fahrenheit = (celsius * 9/5) + 32

print(f"Temperature: {celsius}°C = {fahrenheit}°F")
In [ ]:
# Exercise 3: Working with strings and numbers
hours_worked = 40
hourly_rate = 15.50
total_pay = hours_worked * hourly_rate

employee_info = f"Hours: {hours_worked}, Rate: ${hourly_rate}, Total: ${total_pay}"
print(employee_info)

My Key Takeaways¶

Learning Python's fundamentals has given me a solid foundation for programming. Here's what I consider most important:

  1. Data Types: Understanding int, float, str, and bool helps me choose the right tool for each job
  2. Variables: Descriptive naming makes my code readable and maintainable
  3. Expressions: Combining operators and values lets me perform calculations and logic
  4. Comments: Documenting my thought process helps future me and collaborators
  5. Error Messages: They're not failures but helpful guides toward solutions

These basics are the building blocks for everything else I do in Python. Once I mastered these concepts, more complex topics became much easier to understand.

Copyright © 2025 Mohammad Sayem Chowdhury. This notebook and its content are shared for personal learning and inspiration.


What's Next in My Python Journey¶

Now that I understand the basics, I'm ready to explore more advanced topics like lists, dictionaries, loops, and functions. Each concept builds on these fundamentals, so having a solid grasp of types, variables, and expressions is crucial.

— Mohammad Sayem Chowdhury