Photo AI

Last Updated Sep 26, 2025

Python Programming : Advanced Simplified Revision Notes

Revision notes with simplified explanations to understand Python Programming : Advanced quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

432+ students studying

Python Programming : Advanced

Nested Conditionals

Nested conditionals involve placing one conditional statement inside another. This is useful when you need to check multiple conditions in a hierarchical manner.

For example, an e-commerce platform wants to determine the discount to offer to different customers based on age and membership

  • If the person's age is below 18 or 65 and above, they get a "Senior / Child Discount."
  • If the person's age is 18 or above but below 65:
    • If they are a member, they get a "Member Discount."
    • If they are not a member, they get "No Discount."
age = 45
is_member = True

if age < 18 or age >= 65:
    discount = "Senior / Child Discount"
elif 18 <= age < 65:
    if is_member:
        discount = "Member Discount"
    else:
        discount = "No Discount"

print("Discount : " + discount)

Nested Loops

Nested loops involve placing one loop inside another loop.

list1 = ['a', 'b', 'c']
list2 = [1, 2, 3]

for item1 in list1:
    for item2 in list2:
        print(f"({item1}, {item2})")
        
"""
(a, 1)
(a, 2)
(a, 3)
(b, 1)
(b, 2)
(b, 3)
(c, 1)
(c, 2)
(c, 3)
"""
  • The outer loop (for item1 in list1) iterates over each element in list1.
  • The inner loop (for item2 in list2) iterates over each element in list2 for each value of item1.
  • Each pair (item1, item2) is printed.

Functions

Functions are a fundamental aspect of Python programming. They allow you to encapsulate code into reusable blocks, making your code more modular, readable, and easier to maintain.

We've been using functions this entire time such as print and range. Now we will write our own functions.

The basic syntax of a function is :

def function_name(parameters):
    # Function body
    # Code to execute
    return result  # Optional

Let's write a function that takes in a number, and return the square of that number.

def square(x):
    return x * x

print(square(5))  # Output: 25
print(square(3))  # Output: 9
print(square(2))  # Output: 4

Recursion

infoNote

Recursion is a programming technique where a function calls itself in order to solve smaller instances of the same problem.

It is often used to solve problems that can be broken down into smaller, repetitive tasks. Recursion is a powerful tool, but it must be used with care to avoid infinite loops and stack overflow errors.

A recursive function typically has two main components:

  1. Base Case: The condition under which the function stops calling itself, preventing infinite recursion.
  2. Recursive Case: The part of the function where it calls itself with a smaller or simpler input.

For example, in mathematics, the factorial of a non-negative integer nn is the product of all positive integers less than or equal to nn.

For instance, 5!=5×4×3×2×15! = 5×4×3×2×1. Let's analyse the factorial of 5 closer.

image

We can observe how recursion is used to break down the factorial function into smaller factorials.

  • 5!5! is broken down into 5×4!5×4!
  • 4!4! is broken down into 4×3!4×3! and so on.
  • Eventually, we reach a base case, which is 1.
def factorial(n):
    # Base case: if n is 0, return 1
    if n == 0:
        return 1
    else:
        # Recursive case: return n * factorial(n - 1)
        return n * factorial(n - 1)

Here is a visual representation of the recursive calls :

factorial(4)
 -> 4 * factorial(3)
     -> 3 * factorial(2)
         -> 2 * factorial(1)
             -> 1 * factorial(0)
                 -> 1
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Python Programming : Advanced

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

30 flashcards

Flashcards on Python Programming : Advanced

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

3 quizzes

Quizzes on Python Programming : Advanced

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

4 questions

Exam questions on Python Programming : Advanced

Boost your confidence with real exam questions.

Try Computer Science Questions

27 exams created

Exam Builder on Python Programming : Advanced

Create custom exams across topics for better practice!

Try Computer Science exam builder

27 papers

Past Papers on Python Programming : Advanced

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Python Programming : Advanced you should explore

Discover More Revision Notes Related to Python Programming : Advanced to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Python Programming : Advanced

Python Programming : Advanced

user avatar
user avatar
user avatar
user avatar
user avatar

312+ studying

193KViews
Load more notes

Join 500,000+ Leaving Cert students using SimpleStudy...

Join Thousands of Leaving Cert Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered