About 406,000 results
Open links in new tab
  1. python - Function return with different conditional statement

    Dec 5, 2018 · I have a simple function, which I do like to call and return some values. Inside that function there is a if, elif and else statement, purpose is when if condition is met, return some values, it is when if and elif are not fulfilled, run and display what ever is under else statement.

  2. How do i print the return value for a conditional statement

    Jul 4, 2019 · If you want to keep track of when and how conditions are evaluated, you can do something like this: frame_info = getouterframes(currentframe(), 2)[1] result = re.search(f'{test.__name__}[ ]*\(([^\)]+)\)', frame_info.code_context[1], re.DOTALL) condition = '{} is {}'.format(result.group(1), bool(exp)) print(condition) return bool(exp)

  3. python - Pythonic solution for conditional arguments passing

    Jun 25, 2012 · You can use the ternary if-then operator to pass conditional arguements into functions https://www.geeksforgeeks.org/ternary-operator-in-python/ For example, if you want to check if a key actually exists before passing it you can do something like:

  4. Conditional Statements in Python - GeeksforGeeks

    Apr 4, 2025 · Conditional statements in Python are used to execute certain blocks of code based on specific conditions. These statements help control the flow of a program, making it behave differently in different situations.

  5. 4. More Control Flow Tools — Python 3.13.3 documentation

    2 days ago · Rather than always iterating over an arithmetic progression of numbers (like in Pascal), or giving the user the ability to define both the iteration step and halting condition (as C), Python’s for statement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. For example (no pun intended):

  6. How to Check If a Function Returns a Specific Value in Python

    Summary. In this lab, the first step focuses on understanding function returns in Python. It involves creating a calculate_sum.py script that defines a function, calculate_sum(x, y), which calculates the sum of two input numbers and returns the result using the return statement. The script then calls this function with sample values and prints the returned sum to the console, demonstrating how ...

  7. Python Conditional Statements and Loops

    Conditional Statements in Python. Conditional statements allow your program to make decisions based on certain conditions, executing different blocks of code depending on whether these conditions evaluate to True or False. The if Statement. The most basic conditional statement is the if statement: # Basic if statement x = 10 if x > 5: print("x ...

  8. Python Conditions - W3Schools

    Python Conditions and If statements. Python supports the usual logical conditions from mathematics: Equals: a == b; Not Equals: a != b; Less than: a < b; Less than or equal to: a <= b; Greater than: a > b; Greater than or equal to: a >= b; These conditions can be used in several ways, most commonly in "if statements" and loops.

  9. How to print different outputs based on Python if-else conditions

    The simplest way to print different outputs based on an if-else condition is to use the print() function within the corresponding code blocks. age = 18 if age >= 18: print("You are an adult.") else: print("You are a minor.")

  10. Python If Else Statements - Conditional Statements - Intellipaat

    Apr 3, 2025 · Learn Python if-else statements with examples. Understand conditional statements to control program flow based on different conditions in Python.

  11. Some results have been removed
Refresh