Skip to main content
  1. Notes/
  2. Python 🐍/

πŸ‘Ά Python Basics | Lesson 02

Python Progmramming Course
Table of Contents
Python - This article is part of a series.
Part 2: This Article

πŸ‘Ά Python Basics
#

Welcome to Python Basics! Mastering this chapter will give you the foundation for everything else in programming. Let’s start with the very simple concepts and grow step by step. 🌱


What You’ll Learn 🎯
#

  • Python syntax and indentation
  • Printing messages
  • Basic data types: integers, floats, strings, booleans
  • Variables: storing data
  • Comments

1. Python Syntax & Indentation 🎨
#

  • Python cares about indentation! Indentation (spaces at the start of a line) decides structure in Python.
  • Every new code block (like after :) uses the same indentation.
if True:
    print("Hello!")  # This line is indented

2. Printing Messages πŸ“’
#

Use the print() function to display output.

print("Welcome to Python! 🐍")

Output:

Welcome to Python! 🐍

3. Variables: Storing Data πŸ“¦
#

A variable is a name for a value. Assignment uses =.

name = "Alex"
age = 21
height = 1.75
is_student = True
  • name holds a string ("Alex")
  • age is an integer (21)
  • height is a float (1.75)
  • is_student is a boolean (True)

4. Data Types Explained πŸ”€
#

Data TypeExampleDescription
int5Whole numbers
float3.14Decimal numbers
str"Hello"Text
boolTrueTrue/False values

You can check a variable’s type with type():

print(type(name))    # <class 'str'>
print(type(age))     # <class 'int'>
print(type(height))  # <class 'float'>
print(type(is_student)) # <class 'bool'>

5. Comments πŸ“
#

Use the hash sign (#) to add comments (notes the program ignores).

# This is a comment!
print("Python is fun!")  # This prints a message

Practice Questions with Solutions πŸ†
#

  1. Practice: Create a variable called city that stores your city name and print it.
    • Solution:
city = "Delhi"
print(city)
  1. Practice: What is the output?
a = 10
b = 3.5
print(a + b)
- **Solution:**

13.5 3. Practice: Use comments to describe the line. - Solution:

# Assigning a value to temperature
temperature = 37.5

Step-by-Step Mini Project: Printing a Bio Card 🎫
#

Let’s use what we learned!

# My Bio Card
name = "Sara"
age = 19
is_new_student = True

print("Name:", name)
print("Age:", age)
print("New Student?", is_new_student)

Output:

Name: Sara
Age: 19
New Student? True

Checklist for This Chapter βœ…
#

  • Understood Python indentation
  • Used print() to display output
  • Created and used variables of different types
  • Used comments to clarify code

You’ve just built a strong Python foundation! All set for more awesome skills ahead! πŸš€πŸ‘

Aryan
Author
Aryan
A little bit about you
Python - This article is part of a series.
Part 2: This Article

Related

⏰ Working with Date and Time in Python | Lesson 16
Python Progmramming Course
🎬 Strings in Python | Lesson 04
Python Progmramming Course
πŸ—οΈ Object-Oriented Programming (OOP) Concepts in Python | Lesson 15
Python Progmramming Course
πŸ“„ File Handling in Python | Lesson 14
Python Progmramming Course
πŸ“‹ Lists in Python | Lesson 05
Python Progmramming Course
πŸ“– Dictionaries in Python | Lesson 07
Python Progmramming Course