Introduction to Python & Basic Syntax

Introduction to Python Basic and Syntax

PYTHON PROGRAMMING

Ganesh Medida

4/13/20253 min read

black flat screen computer monitor
black flat screen computer monitor

🎉 Welcome to Day 1 of Your Python Journey! 🎉

Embarking on your Python adventure is like opening the door to endless possibilities in coding! Whether you're a beginner or curious about programming, this guide will make Python approachable and downright fun. By the end of today’s lesson, you’ll write your first Python program, use Python as a powerful calculator, and understand foundational programming concepts. Let’s dive in!

Why Python is Your Perfect Starting Point

Think of Python as your reliable companion—friendly, versatile, and full of surprises. It's widely used in industries like data science, artificial intelligence, web development, automation, and beyond. The best part? It’s designed to be beginner-friendly while remaining incredibly effective for advanced projects.

Fun Fact: Did you know Python was named after the comedy show "Monty Python's Flying Circus"? Its creator wanted programming to feel lighthearted and enjoyable—just like this course!

Communicating with Your Computer

Let’s start by teaching Python to talk! The simplest way to communicate is through the print() function.

Your First Python Program

print("Hello, World!")

Run this code, and watch Python greet you with:

Hello, World!

Congratulations—you’ve written your first program! 🎉

Add Some Personality

Let’s make it more personal. Customize the message:

print("Hi, my name is Alex!") print("I love learning new things.") print("Python is my favorite language!")

Python as Your Super Calculator

Did you know Python is also a math wizard? Let's explore how Python handles numbers!

Basic Math Operations:

# Addition print(8 + 3) # Output: 11 # Subtraction print(15 - 5) # Output: 10 # Multiplication print(6 7) # Output: 42 # Division print(10 / 2) # Output: 5.0 # Integer Division print(10 // 3) # Output: 3 # Modulus (Remainder) print(10 % 3) # Output: 1 # Exponentiation (Power) print(2 * 4) # Output: 16

Combine Operations:

You can mix and match operations to solve more complex math problems:

result = (8 + 3) * (15 / 5) print(result) # Output: 33.0

Practical Example: Calculating Area

Here’s how you can use Python to calculate the area of a rectangle:

length = 12 width = 8 area = length * width print(f"The area of the rectangle is {area}.") # Output: 96

Variables—Python's Memory Bank

Variables are like labeled containers that hold your data. Instead of typing information repeatedly, you store it once and reuse it.

Example of Variables:

name = "Charlie"

age = 30

favorite_hobby = "painting"

Now, use them in your program:

print(f"My name is {name}.") print(f"I’m {age} years old.") print(f"My favorite hobby is {favorite_hobby}.")

Variables make your code dynamic, reusable, and much cleaner!

Quick Cheat Sheet

Here’s a handy reference for the concepts covered today:

  • Print () Function: Displays messages, numbers, or variables.

    print("Hello, World!")

  • Comments: Add notes to your code for clarity.

    # This explains the purpose of the code below.

  • Math Operations: Perform calculations using Python.

    + Add numbers

    - Subtract numbers

    * Multiply numbers

    \ / Divide numbers

    % Find remainder

    ^ Exponentiation

  • Variables: Store values to reuse later.

    name = "Alice" age = 25

  • F-Strings: Format strings dynamically.

    print(f"My name is {name} and I am {age} years old.")

Fun and Creative Challenges

Let’s take Python for a spin with some fun mini-projects:

Challenge 1: Draw Shapes

print("*****")

print("* *")

print("* ")

print("****")

Challenge 2: Personalized Greetings

name = input("What's your name? ") print(f"Hello, {name}! Welcome to Python!")

Challenge 3: Magic Calculator

number = int(input("Enter a number: ")) square = number ** 2 print(f"The square of {number} is {square}.")

Highlights from Day 1

  • You’ve learned the basics of Python syntax.

  • You wrote your first program and used Python as a calculator.

  • You discovered how variables work and make code reusable.

Homework to Boost Your Skills

  1. Write a Python program that introduces you and calculates your age based on your birth year.
  2. Play with arithmetic operations and find creative ways to combine them.
  3. Add comments to your code and explain what each line does.

Sneak Peek at Day 2

"Today, you’ve unlocked Python’s ability to communicate and calculate. Tomorrow, we’ll dive deeper into how Python remembers things with advanced variable manipulation—and maybe even have some fun with logic!"

Enjoy your Python adventure—you’re off to a fantastic start! 🌟