Avatar ·

The return statement in a try/except/finally block

📁 function, Advanced Python Topics, AI

There is this function:

def f():    try:        1 / 0    except:        retu 1    finally:        retu 2    retu 3

When run, it returns 2, even though after the exception occurs it should go into the except block, where 1 is returned. Doesn't return interrupt the function execution?

Avatar ·

"

The print() function has the following keyword parameters:

  • sep= – when multiple values are printed, which character or string to separate them with
    (default is a space, i.e., the string ' '),

  • end= – which character or string to print after printing (all) values
    (default is a newline, i.e., the string ''),

  • file= – which file to output the values to
    (default is the screen, i.e., sys.stdout),

  • flush= – immediately flush the stream (saved in the buffer) to the file
    (default is "no", i.e., False).

In your case, you want to stay on the same line after printing the value.

Log in to leave an answer

Blogs