Describe Python and where it is used.
π Python Foundations
Understand what Python is, how it runs a program, and the small set of syntax rules you need before solving your first problems.
# My first Python program
name = "Venu"
goal = "learn Python"
print(f"Hello, {name}!")
print(f"Today I will {goal}.")
Today I will learn Python.
By the End of This Level
You will be able to explain and write the foundations of a Python program.
Explain source code, interpreter and output.
Run Python using IDLE, VS Code or an online editor.
Use print(), indentation and comments correctly.
What Is Python?
Python is a high-level, general-purpose programming language designed to make programs easy to read and write. Instead of managing many low-level details, you can focus on the problem and its solution.
Python is a language used to give clear instructions to a computer.
Readable
Its syntax looks close to normal English and uses fewer symbols.
Interpreted
An interpreter executes the program without a separate manual compilation step.
Portable
The same program can run on Windows, Linux and macOS with little or no change.
Rich Ecosystem
Thousands of libraries support web, automation, data science, AI and more.
How Python Runs a Program
You write instructions in a .py file. The Python interpreter reads them and performs the requested operations.
hello.pyPython normally executes statements from top to bottom. If it finds an error, it stops and shows a message that helps locate the problem.
Three Easy Ways to Run Python
π Python IDLE
Installed with Python. It includes an interactive shell and a simple editor.
- Install Python 3 from python.org.
- Open IDLE.
- Select File β New File.
- Save as
hello.pyand press F5.
π§βπ» VS Code
A flexible editor with the official Python extension, terminal and debugging tools.
- Install Python 3 and VS Code.
- Install the Python extension.
- Create a
.pyfile. - Click Run Python File.
π Online Editor
Useful for quick practice when you cannot install software on the computer.
- Open a trusted Python editor.
- Choose Python 3.
- Type your program.
- Click Run and inspect the output.
Open Command Prompt and run python --version. If Windows uses the launcher, try py --version. Continue with a Python 3 version.
Display Output with print()
print() is a built-in Python function. It displays text, numbers or calculated values on the screen.
Hello, CodeBhavya!
print("Hello, CodeBhavya!")
print("I am learning Python.")
Hello, CodeBhavya! I am learning Python.
Print Text, Numbers and a Calculation
print("My age is", 35)
print("10 + 5 =", 10 + 5)
print("Python", "is", "easy")
My age is 35 10 + 5 = 15 Python is easy
What Happens During Execution?
| Step | Statement | Python's action | Output so far |
|---|---|---|---|
| 1 | print("My age is", 35) | Displays the two values with a space. | My age is 35 |
| 2 | print("10 + 5 =", 10 + 5) | Calculates 15, then displays it. | 10 + 5 = 15 |
| 3 | print("Python", "is", "easy") | Displays three strings separated by spaces. | Python is easy |
Python Syntax and Case Sensitivity
One Statement per Line
print("First")
print("Second")Quotes Must Match
print("Correct")
print('Also correct')Python Is Case-Sensitive
name = "Bhavya"
Name = "Python"name and Name are different.
Parentheses Must Balance
print("Balanced")print("Welcome")Matching quotes and closing parenthesis.
Print("Welcome")Print is not the same as print.
Indentation in Python
Indentation means spaces at the beginning of a line. Python uses indentation to group statements that belong together. Most Python style uses four spaces for one indentation level.
is_ready = True
if is_ready:
print("Start learning")
print("Program finished")The indented statement belongs to the if block.
is_ready = True
if is_ready:
print("Start learning")Python expects an indented block after the colon.
Do not mix tabs and spaces. Configure your editor to insert four spaces when you press Tab.
Comments
A comment is a note for people reading the code. Python ignores a single-line comment beginning with #.
Useful Comments
# Display the course name
print("CodeBhavya Python")
# Calculate the total number of classes
weeks = 4
classes_per_week = 3
print(weeks * classes_per_week)
CodeBhavya Python 12
Explain why a non-obvious step is needed.
Keep the comment short and update it when code changes.
Avoid comments that merely repeat an obvious statement.
Common Beginner Mistakes
print("Hello)The opening and closing quotes do not match.
Print("Hello")Python does not know a function named Print.
if True:print("Yes")The statement after the colon must be indented.
π Python Foundations β Quick Revision
Review the complete Level 1 lesson in two minutes before attempting the quiz and programming problems.
Python is a readable, high-level and general-purpose programming language.
A Python source file normally uses the .py extension.
The Python interpreter reads and executes program instructions.
Statements normally execute from top to bottom.
print() displays text, numbers and calculated results.
Text values must be written inside matching single or double quotes.
Python is case-sensitive: print and Print are different.
Indentation groups statements; four spaces are the standard style.
A single-line comment begins with the # symbol.
Read an error using its type, line number, message and marked code.
Level 1 Quick Quiz
Select one answer for every question, then check your score.
Level 1 Practice
Type and run each program before opening the solution.
Personal Introduction
Print your name, department and goal on three separate lines.
Sample outputMy name is Venu
Department: CSE-AI&ML
Goal: Learn Python
print("My name is Venu")
print("Department: CSE-AI&ML")
print("Goal: Learn Python")Decorative Course Card
Use multiple print() calls to display a simple course title inside a border made with equal signs.
Sample output====================
CODEBHAVYA PYTHON
====================
print("====================")
print(" CODEBHAVYA PYTHON")
print("====================")Predict the Output
Write the output without running the program first.
print("Result:", 8 + 2)
print("Python" * 2)
Result: 10
PythonPythonCorrect the Errors
Find and correct every error in this program.
Print("Welcome to Python")
print("Let us learn Python)
if True:
print("Ready")
print("Welcome to Python")
print("Let us learn Python")
if True:
print("Ready")π― 5 Programming Problems β Python Foundations
Try every problem yourself first. Open π» Solve It Yourself to write and test your program, use Hint only when required, and open Show Program to study the official solution.
A problem counts as Solved when its output passes before the official solution is opened.
Write a Python program that displays the exact welcome message.
Hello, Python!print().Python Code Editor
Program Output
Run your program to see the output.
Test Case
print("Hello, Python!")Display the student's name, course and learning goal on separate lines.
print() statements.Python Code Editor
Program Output
Run your program to see the output.
Test Case
print("Name: Venu")
print("Course: Python Foundations")
print("Goal: Build strong basics")Display the label 10 + 5 = followed by the calculated result.
10 + 5 = 15print() one string value and one expression separated by a comma.Python Code Editor
Program Output
Run your program to see the output.
Test Case
print("10 + 5 =", 10 + 5)Create a three-line banner using equal signs and the course name.
print() statements and match the spaces exactly.Python Code Editor
Program Output
Run your program to see the output.
Test Case
print("====================")
print(" CODEBHAVYA PYTHON")
print("====================")Correct the function name and indentation so both messages are displayed.
Ready and Program finishedif and remember that Python is case-sensitive.Python Code Editor
Program Output
Run your program to see the output.
Test Case
if True:
print("Ready")
print("Program finished")π― Think Clearly Before You Code
What result should the program produce?
Express the solution using clear Python statements.
Let the interpreter execute the statements.
Compare the actual output with the expected output.
π¬ Python Program β Visual Flow
Follow a Python program from the moment you write the source code until you inspect its result.
π How a Python Program Runs
1. Write Clear Source Code
Create readable Python instructions using correct syntax, matching quotes and consistent indentation.
π Program Tracing β Python Foundations
Move through the program one statement at a time and observe how values and output change.
Click Next to begin tracing.
β
π€ Python Foundations β Interview Questions
Try to answer aloud before opening each explanation.
What makes Python a high-level programming language?
Python hides many low-level hardware and memory details, allowing programmers to express solutions using readable instructions and built-in facilities.
What is the role of the Python interpreter?
The interpreter reads Python source code, checks it and executes its instructions, producing either the requested result or an error message.
Why is indentation important in Python?
Indentation defines blocks of related statements. Incorrect indentation can change the program structure or cause an IndentationError.
Is Python case-sensitive? Give one example.
Yes. For example, print is the built-in output function, while Print is treated as a different and normally undefined name.
What can the print() function display?
It can display strings, numbers, Boolean values, calculated expressions and multiple values supplied as arguments.
How do comments help a Python program?
Comments document the purpose or reasoning of code for human readers. A single-line Python comment begins with # and is ignored during normal execution.
π‘ Python Foundations β Extra Tips
- 01
Type every example yourself; typing develops syntax memory faster than reading alone.
- 02
Use meaningful filenames such as
first_program.pyinstead of vague names. - 03
Run the program after small changes so errors are easier to locate.
- 04
Read error messages from the last line first to identify the error type and message.
- 05
Use four spaces consistently and configure the editor to convert Tab into spaces.
- 06
Predict the output before running a program; this builds strong tracing ability.
βοΈ Python Foundations β Extra Practice Questions
- Write a program that displays your name and city on separate lines.
- Print the words
Learn,PracticeandBuildusing oneprint()call. - Display the result of
25 + 15with a suitable label. - Create a five-line profile card using only
print()statements. - Write two valid comments explaining the purpose of a small program.
- Predict the output of
print("Code" * 3)before running it. - Correct this statement:
Print('Python'). - Correct the missing quote in
print("Welcome). - Write a correctly indented
if True:block that printsLearning. - Create and run a
.pyfile, then explain the source-code-to-output flow in your own words.
Python Foundations Complete
When you can explain the execution flow and write the practice programs without help, mark this level complete and continue.