Determine if python is being run in Ubuntu Linux

The currently accepted answer uses a deprecated function. The proper way to do this as of Python 2.6 and later is:

import platform
print(platform.linux_distribution())

The documentation doesn't say if this function is available on non-Linux platforms, but on my local Windows desktop I get:

>>> import platform
>>> print(platform.linux_distribution())
('', '', '')

There's also this, to do something similar on Win32 machines:

>>> print(platform.win32_ver())
('post2008Server', '6.1.7601', 'SP1', 'Multiprocessor Free')

Looks like platform.dist() and platform.linux_distribution() are deprecated in Python 3.5 and will be removed in Python 3.8. The following works in Python 2/3

import platform
'ubuntu' in platform.version().lower()

Example return value

>>> platform.version()
'#45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022'