FREE E LEARNING PLATFORM
☰ HOMEEXCEPTIONSOOPSJVMINTRO
×

Python Syllabus

AKTU Python Syllabus AKTU Python Freshers AKTU Python Advanced AKTU Pyton PYQ AKTU Pyton PYQS 2026 AKTU Pyton PYQS 2025 AKTU Pyton PYQS 2024

Unit I Introduction

Introduction to Python History of Python Features of Python Applications of Python Python Installation Python IDE Python Program Life Cycle First Python Program Blocks & Indentation Comments Keywords Identifiers Variables Input & Output Data Types Numeric Data Types Type Conversion Python Operators

Unit II Control Statements

if Statement if...else Statement Nested if elif Statement for Loop range() Function while Loop Nested Loops break Statement continue Statement pass Statement else with Loop

Unit III Complex Data Types

Strings String Operations String Methods String Built-in Functions Lists List Slicing List Methods List Built-in Functions Tuples Tuple Methods Dictionaries Dictionary Methods Dictionary Built-in Functions Python Built-in Functions Python Functions User Defined Functions Lambda Functions Recursive Functions

Unit IV File Handling

Introduction to File Handling open() read() readline() readlines() write() writelines() File Pointer seek() tell() File Modes

Unit V Packages & GUI

Modules Packages NumPy Pandas Matplotlib Tkinter Introduction Tkinter Widgets Button Widget Label Widget Entry Widget Frame Widget Menu Widget Event Handling Programming with IDE Tkinter Mini Project

Python Programs

100+ Solved Programs Pattern Programs File Programs Tkinter Programs

AKTU Questions

Unit I Questions Unit II Questions Unit III Questions Unit IV Questions Unit V Questions Viva Questions Python MCQs

Previous Papers

AKTU 2026 (Solved) AKTU 2025 (Solved) AKTU 2024 (Solved) AKTU 2023 (Solved) AKTU 2022 (Solved)
 


Python if Statement

The if statement is used to execute a block of code only when a specified condition is True. It is one of the basic decision-making statements in Python.

The if statement evaluates a condition. If the condition is true, the statements inside the if block are executed. If the condition is false, the block is skipped.

Syntax of if Statement

if condition:
    statement

The colon : after the condition indicates the beginning of the if block. Python uses indentation to identify the statements belonging to the block.


Simple if Statement

age = 20

if age >= 18:
    print("You are eligible to vote.")
Output:
You are eligible to vote.

Since age >= 18 is True, the print() statement is executed.


if Statement with a False Condition

age = 15

if age >= 18:
    print("You are eligible to vote.")

print("Program completed.")
Output:
Program completed.

The condition is false, so the statement inside the if block is not executed. The statement outside the block is executed.


if Statement with Comparison Operators

Comparison operators can be used to create conditions in an if statement.

marks = 75

if marks >= 40:
    print("Pass")
Output:
Pass

The condition marks >= 40 evaluates to True, so the message is displayed.


if Statement with Equality Operator

number = 10

if number == 10:
    print("Number is 10")
Output:
Number is 10
Important: Use == to compare two values. The single = operator is used for assignment.

if Statement with Logical Operators

Logical operators such as and, or and not can be used to combine conditions.

Using and

age = 25

if age >= 18 and age <= 60:
    print("Eligible")
Output:
Eligible

Using or

day = "Sunday"

if day == "Saturday" or day == "Sunday":
    print("Weekend")
Output:
Weekend

Using not

is_raining = False

if not is_raining:
    print("You can go outside.")
Output:
You can go outside.

if Statement with User Input

The input() function can be used to accept a value from the user and then apply a condition.

age = int(input("Enter your age: "))

if age >= 18:
    print("You are an adult.")
Example:
Enter your age: 21
You are an adult.

Checking Positive Number

number = int(input("Enter a number: "))

if number > 0:
    print("Positive number")
Example:
Enter a number: 25
Positive number

Checking Even Number

The modulus operator % can be used to determine whether a number is even.

number = int(input("Enter a number: "))

if number % 2 == 0:
    print("Even number")
Example:
Enter a number: 20
Even number

Checking Whether a String is Empty

An empty string evaluates to False in a Boolean context.

name = input("Enter your name: ")

if name:
    print("Name entered:", name)
Example:
Enter your name: Rahul
Name entered: Rahul

if Statement with Membership Operator

The in operator can be used to check whether an item exists in a sequence.

fruits = ["apple", "banana", "mango"]

if "mango" in fruits:
    print("Mango is available.")
Output:
Mango is available.

Nested if Statement

An if statement inside another if statement is called a nested if statement.

age = 25
has_id = True

if age >= 18:
    if has_id:
        print("Entry allowed.")
Output:
Entry allowed.

The inner if statement is checked only when the outer condition is true.


Multiple Statements inside if Block

More than one statement can be placed inside an if block. All statements must have the same indentation.

marks = 85

if marks >= 40:
    print("Result: Pass")
    print("Congratulations!")
    print("You have cleared the examination.")
Output:
Result: Pass
Congratulations!
You have cleared the examination.

Importance of Indentation

Python uses indentation to define a block of code. Statements belonging to the if block must be indented.

age = 20

if age >= 18:
    print("Adult")
    print("Eligible")

In this example, both print() statements belong to the if block because they have the same indentation.

Warning: Incorrect indentation can cause an IndentationError or change the logical structure of the program.

if Statement with Multiple Conditions

marks = 85

if marks >= 40 and marks <= 100:
    print("Valid passing marks")
Output:
Valid passing marks

Checking a Number in a Range

Python allows comparison expressions to be chained.

number = 50

if 1 <= number <= 100:
    print("Number is between 1 and 100.")
Output:
Number is between 1 and 100.

Practical Example: Discount Eligibility

amount = float(input("Enter purchase amount: "))

if amount >= 5000:
    print("You are eligible for a discount.")
Example:
Enter purchase amount: 6500
You are eligible for a discount.

Practical Example: Pass Check

marks = int(input("Enter marks: "))

if marks >= 40:
    print("Pass")
Example:
Enter marks: 72
Pass

if Statement vs if-else Statement

if Statement if-else Statement
Executes a block only when the condition is true. Provides blocks for both true and false conditions.
No alternative block is provided. An else block provides an alternative.
Useful when an action is required only for a true condition. Useful when one of two alternatives must be selected.

The if-else statement is discussed in the next tutorial.


Important Points

  • The if statement is used for decision making.
  • The condition is evaluated as either True or False.
  • The colon : is required after the condition.
  • Statements inside the if block must be indented.
  • Comparison operators can be used to create conditions.
  • Logical operators can combine multiple conditions.
  • An if statement can be nested inside another if statement.
  • The if statement does not provide an alternative block when the condition is false.
Key Point: The Python if statement executes a block of code only when its condition evaluates to True. Python uses indentation to define the statements belonging to the if block.