Find out if my code runs inside a notebook or jupyter lab?

Update: I read that as “Is there a way to find out if my code is running inside a jupyter notebook vs. jupyter lab?” Sorry. After you posted a valid solution for a notebook vs. a script, I then posted & linked below what I should have posted here. But I’m leaving my original response here addressing detecting if running in the classic notebook vs. JupyterLab because how to determine that has been raised as a question a few times.

I haven’t found the answer to that yet; however, to encourage one, I’ll point out by listing the examples I found that this question (or very similar variants) has been raised on StackOverflow & on this discourse in the past a few times with no clear answer. We should then update these to maybe point to such an answer:

1 Like