Skip to content
Felix
  • Topics
    • My List
    • Felix Guide
    • Asset Management
    • Coding and Data Analysis
      • Data Analysis and Visualization
      • Financial Data Tools
      • Python
      • SQL
    • Credit
      • Credit Analysis
      • Restructuring
    • Financial Literacy Essentials
      • Financial Data Tools
      • Financial Math
      • Foundations of Accounting
    • Industry Specific
      • Banks
      • Chemicals
      • Consumer
      • ESG
      • Insurance
      • Oil and Gas
      • Pharmaceuticals
      • Project Finance
      • Real Estate
      • Renewable Energy
      • Technology
      • Telecoms
    • Introductory Courses
    • Investment Banking
      • Accounting
      • Financial Modeling
      • M&A and Divestitures
      • Private Debt
      • Private Equity
      • Valuation
      • Venture Capital
    • Markets
      • Economics
      • Equity Markets and Derivatives
      • Fixed Income and Derivatives
      • Introduction to Markets
      • Options and Structured Products
      • Other Capital Markets
      • Securities Services
    • Microsoft Office
      • Excel
      • PowerPoint
      • Word & Outlook
    • Professional Skills
      • Career Development
      • Expert Interviews
      • Interview Skills
    • Risk Management
    • Transaction Banking
    • Felix Live
  • Pathways
    • Investment Banking
    • Asset Management
    • Equity Research
    • Sales and Trading
    • Commercial Banking
    • Engineering
    • Operations
    • Private Equity
    • Credit Analysis
    • Restructuring
    • Venture Capital
    • CFA Institute
  • Certified Courses
  • Ask An Instructor
  • Support
  • Log in
  • Topics
    • My List
    • Felix Guide
    • Asset Management
    • Coding and Data Analysis
      • Data Analysis and Visualization
      • Financial Data Tools
      • Python
      • SQL
    • Credit
      • Credit Analysis
      • Restructuring
    • Financial Literacy Essentials
      • Financial Data Tools
      • Financial Math
      • Foundations of Accounting
    • Industry Specific
      • Banks
      • Chemicals
      • Consumer
      • ESG
      • Insurance
      • Oil and Gas
      • Pharmaceuticals
      • Project Finance
      • Real Estate
      • Renewable Energy
      • Technology
      • Telecoms
    • Introductory Courses
    • Investment Banking
      • Accounting
      • Financial Modeling
      • M&A and Divestitures
      • Private Debt
      • Private Equity
      • Valuation
      • Venture Capital
    • Markets
      • Economics
      • Equity Markets and Derivatives
      • Fixed Income and Derivatives
      • Introduction to Markets
      • Options and Structured Products
      • Other Capital Markets
      • Securities Services
    • Microsoft Office
      • Excel
      • PowerPoint
      • Word & Outlook
    • Professional Skills
      • Career Development
      • Expert Interviews
      • Interview Skills
    • Risk Management
    • Transaction Banking
    • Felix Live
  • Pathways
    • Investment Banking
    • Asset Management
    • Equity Research
    • Sales and Trading
    • Commercial Banking
    • Engineering
    • Operations
    • Private Equity
    • Credit Analysis
    • Restructuring
    • Venture Capital
    • CFA Institute
  • Certified Courses
Felix
  • Data
    • Company Analytics
    • My Filing Annotations
    • Market & Industry Data
    • United States
    • Relative Valuation
    • Discount Rate
    • Building Forecasts
    • Capital Structure Analysis
    • Europe
    • Relative Valuation
    • Discount Rate
    • Building Forecasts
    • Capital Structure Analysis
  • Models
  • Account
    • Edit my profile
    • My List
    • Restart Homepage Tour
    • Restart Company Analytics Tour
    • Restart Filings Tour
  • Log in
  • Ask An Instructor
    • Email Our Experts
    • Felix User Guide
    • Contact Support

Custom Functions, For Loops, Conditional Logic

Create your own custom functions in Python. Learn how to repeat tasks through iterable objects using for loops, and incorporate conditional logic using if statements.

Unlock Your Certificate   
 
0% Complete

11 Lessons (35m)

Show lesson playlist
  • Description & Objectives

  • 1. Custom Functions Learning Objectives

    00:19
  • 2. Creating Custom Functions

    07:51
  • 3. Custom Functions Workout

    02:13
  • 4. Adding Arguments

    03:09
  • 5. For Loops

    04:04
  • 6. Adding Arguments Workout

    03:07
  • 7. Filling a List with a For Loop

    03:20
  • 8. For Loops Workout

    02:37
  • 9. Conditional Logic

    04:48
  • 10. Conditional Logic Workout

    03:44
  • 11. Custom Functions Review

    00:25

Prev: Python Objects Next: NumPy

Conditional Logic

  • Notes
  • Questions
  • Transcript
  • 04:48

How conditional logic is used in Python, specifically focusing on how to use if statements, else statements, and elif statements.

Downloads

No associated resources to download.

Glossary

Conditional Logic elif statements else statements If statements Python
Back to top
Financial Edge Training

© Financial Edge Training 2025

Topics
Introduction to Finance Accounting Financial Modeling Valuation M&A and Divestitures Private Equity
Venture Capital Project Finance Credit Analysis Transaction Banking Restructuring Capital Markets
Asset Management Risk Management Economics Data Science and System
Request New Content
System Account User Guide Privacy Policy Terms & Conditions Log in
Transcript

Conditional logic allows you to write more complex and useful applications that evaluate and respond to conditions that you define. You can create conditional logic using if statements, if statements, begin with the if keyword and have two parts. First, the condition to evaluate, which must be either true or false. And second, a code block to execute if the condition is true, which must be indented without conditional logic. You could use a for loop like we have right here to print all of the objects in a list by adding an if statement. You could incorporate conditional logic here. I have another for loop that iterates through all of the objects in list one, but inside of that for loop, I also have an if statement. Now you have this percentage sign, which we haven't talked about before. That's the modulo operator, and it checks to see that when this number is divided by 2, what the remainder is. So my if statement evaluates if the number when divided by 2 has a remainder of 0 and then a colon tells it in this indented code block, what to do if that, if that condition is true? So if the number divided by 2 has a remainder of 0, then print the number, which is really the same as saying print all of the even numbers only in list one. When I execute that code cell, it's gonna apply our conditional logic and it's gonna print only the even numbers 2 and 4. You can also add code to run if the condition is false by adding an else statement. For example, if we wanted to, we could use an if statement and an else statement to split list one into a list of even numbers and a list of odd numbers. So here I've initialized two lists, even numbers and odd numbers. Now I wanna write a for loop that cycles through each object in list one evaluates whether it's even or whether it's odd, and then puts even numbers into my list, even numbers and odd numbers into my list. Odd numbers. So I'm gonna start by saying four number in list one if that number, and then I'm gonna use that modulo symbol. If when divided by 2, the remainder is equal to 0, meaning that it's an even number, then I want to add it to my list, even numbers. So I'm gonna say even numbers, append that number. Else, if that condition is not met, I want to append to my list odd numbers. Once that's done, I want to print both of my lists and now we can check to see if our numbers were split correctly. There you go. It looks like even numbers does contain the even numbers 2 and 4 and odd numbers contains 1, 3, and 5. Your conditional logic is not limited to two options. If and else, you can add intermediate steps using elif statements, which is a combination of else. And if so, you can have, if this first condition is true, then do A, elif else if the second condition is true, then do B, else finally do C If both of those are not true, for example, let's say we wanted to split list two here into positive numbers and negative numbers. Here I've created the list, I've initialized two other lists for positive numbers and negative numbers, and then I've written a quick for loop containing an if statement and an else statement. And it says, for each number in list two, if that number is greater than 0, then append it to our positive list else, append it to our negative list. And when I print those out, we're gonna see that 0 did not get put in the right list because we only have that one condition. We're saying if the number is greater than 0, which is one and two, then append it to positive list list, otherwise append it to negative list. Well, technically it's true that 0 is not greater than 0, so it goes into our negative list, even though it's not a negative number. If we want to fix that, we'll need to add another condition with an elif statement. So first I'm going to initialize a list called 0, and that'll give us a place to store 0. After we add this elif statement, I'm gonna change the second statement to an elif statement, and it's gonna say else if that number is less than 0, then we want to append it to our negative list.

And finally, so we've sorted out the numbers that are greater than 0. We've sorted out the numbers that are less than 0, so else all we have left is 0. Then we will append that to our list called 0.

And now I wanna print my positive list, my negative list, and I also wanna print my list called 0. And then you can see that all of the numbers have been sorted into the correct list.

Content Requests and Questions

You are trying to access premium learning content.

Discover our full catalogue and purchase a course Access all courses with our premium plans or log in to your account
Help

You need an account to contact support.

Create a free account or log in to an existing one

Sorry, you don't have access to that yet!

You are trying to access premium learning content.

Discover our full catalogue and purchase a course Access all courses with our premium plans or log in to your account

You have reached the limit of annotations (10) under our premium subscription. Upgrade to unlock unlimited annotations.

Find out more about our premium plan

You are trying to access content that requires a free account. Sign up or login in seconds!

Create a free account or log in to an existing one

You are trying to access content that requires a premium plan.

Find out more about our premium plan or log in to your account

Only US listed companies are available under our Free and Boost plans. Upgrade to Pro to access over 7,000 global companies across the US, UK, Canada, France, Italy, Germany, Hong Kong and more.

Find out more about our premium plan or log in to your account

A pro account is required for the Excel Add In

Find out more about our premium plan

Congratulations on completing

This field is hidden when viewing the form
Name(Required)
This field is hidden when viewing the form
Rate this course out of 5, where 5 is excellent and 1 is terrible.
Were the stated learning objectives met?(Required)
Were the stated prerequisite requirements appropriate and sufficient?(Required)
Were the program materials, including the qualified assessment, relevant and did they contribute to the achievement of the learning objectives?(Required)
Was the time allotted to the learning activity appropriate?(Required)
Are you happy for us to use your feedback and details in future marketing?(Required)

Thank you for already submitting feedback for this course.

CPE

What is CPE?

CPE stands for Continuing Professional Education, by completing learning activities you earn CPE credits to retain your professional credentials. CPE is required for Certified Public Accountants (CPAs). Financial Edge Training is registered with the National Association of State Boards of Accountancy (NASBA) as a sponsor of continuing professional education on the National Registry of CPE Sponsors.

What are CPE credits?

For self study programs, 1 CPE credit is awarded for every 50 minutes of elearning content, this includes videos, workouts, tryouts, and exams.

CPE Exams

You must complete the CPE exam within 1 year of accessing a related playlist or course to earn CPE credits. To see how long you have left to complete a CPE exam, hover over the locked CPE credits button.

What if I'm not collecting CPE credits?

CPE exams do not count towards your FE certification. You do not need to complete the CPE exam if you are not collecting CPE credits, but you might find it useful for your own revision.


Further Help
  • Felix How to Guide walks you through the key functions and tools of the learning platform.
  • Playlists & Tryouts: Playlists are a collection of videos that teach you a specific skill and are tested with a tryout at the end. A tryout is a quiz that tests your knowledge and understanding of what you have just learned.
  • Exam: If you are collecting CPE points you must pass the relevant CPE exam within 1 year to receive credits.
  • Glossary: A glossary can be found below each video and provides definitions and explanations for terms and concepts. They are organized alphabetically to make it easy for you to find the term you need.
  • Search function: Use the Felix search function on the homepage to find content related to what you want to learn. Find related video content, lessons, and questions people have asked on the topic.
  • Closed Captions & Transcript: Closed captions and transcripts are available on videos. The video transcript can be found next to the closed captions in the video player. The transcript feature allows you to read the transcript of the video and search for key terms within the transcript.
  • Questions: If you have questions about the course content, you will find a section called Ask a Question underneath each video where you can submit questions to our expert instructor team.