Showing posts with label beginner coding class. Show all posts
Showing posts with label beginner coding class. Show all posts

Monday, March 16, 2026

Lesson 2: Variables, Data Types, and Basic Operations | Coding Class Series

March 16, 2026 0

 


Lesson 2: Variables, Data Types, and Basic Operations

Introduction:
Welcome to Lesson 2 of our Coding Class Series! In this lesson, we will learn the fundamentals of Variables, Data Types, and Basic Operations. These are the building blocks of any programming language and essential for writing your first programs.


1️⃣ Variables

A variable is like a container that stores data which can change during program execution.

Example in Python:

name = "Alice"      # String variable
age = 20            # Integer variable
is_student = True   # Boolean variable

Tips:

  • Variable names should be meaningful (e.g., user_age instead of x).
  • No spaces in variable names; use underscores _ instead.

2️⃣ Data Types

A data type defines what kind of value a variable holds. Common types include:

Data Type Example Description
Integer 10 Whole numbers
Float 3.14 Decimal numbers
String "Hello" Text values
Boolean True / False Logical values

3️⃣ Basic Operations

Operations allow you to work with variables and values.

Arithmetic Operations:

a = 10
b = 5
print(a + b)   # 15
print(a - b)   # 5
print(a * b)   # 50
print(a / b)   # 2.0
print(a % b)   # 0 (remainder)

String Operations:

first_name = "Alice"
last_name = "Smith"
full_name = first_name + " " + last_name
print(full_name)  # Alice Smith

Boolean Operations:

is_raining = True
has_umbrella = False
print(is_raining and has_umbrella)  # False
print(is_raining or has_umbrella)   # True

4️⃣ Practice Exercises

  1. Create a variable city and assign your city name to it.
  2. Add two numbers using variables and print the result.
  3. Create a boolean variable is_hungry and test it with logical operations.
  4. Combine two strings using concatenation.

Remember: Practice makes coding easy and fun!