---
title: "Python 2 | CoderPad"
description: "Learn more about Python 2 from CoderPad."
canonical: "https://coderpad.io/languages/python-2/"
last_modified: "2023-03-30 19:53:39"
---
# Python 2 online IDE & code editor for technical interviews

Running CPython 2.7 – IntelliSense is enabled

### Experience the Python 2 IDE yourself

See just how easy and intuitive CoderPad Interview is to use below.

[Launch the environment](https://embed.coderpad.io/sandbox?language=python)

## Guidelines to use Python 2 in this online IDE

The Python environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses [IPython](http://ipython.org/) to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for importing are:

- [requests](https://requests.readthedocs.io/en/master/) for simpler HTTP requests.
- [beautifulsoup4](https://pypi.org/project/beautifulsoup4/) for HTML parsing.
- [numpy](http://www.numpy.org/), [scipy](http://www.scipy.org/), [pandas](http://pandas.pydata.org/), [scikit-learn](http://scikit-learn.org/), and [statsmodels](https://www.statsmodels.org/) for advanced numerical analysis. Unfortunately, plotting does not work in CoderPad’s purely textual interface at this time.

### Testing

We’ve got a few ways you can test your Python code in CoderPad:

1. The [unittest](https://docs.python.org/2/library/unittest.html) library that ships with Python by default. Here’s a quick example:

```
import unittest

class TestStringMethods(unittest.TestCase):
    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # s.split should throw when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)

unittest.main(exit=False)Code language: Python (python)
```
1. [pytest](https://pytest.org/en/latest/). The above snippet of code would look like the following when written for pytest:

```
import pytest

def test_upper():
    assert 'foo'.upper() == 'FOO'

def test_isupper():
    assert 'FOO'.isupper()
    assert not 'Foo'.isupper()

def test_split():
    s = 'hello world'
    assert s.split() == ['hello', 'world']
    # s.split should throw when the separator is not a string
    with pytest.raises(TypeError):
        s.split(2)

pytest.main()Code language: Python (python)
```
1. [mock](https://github.com/testing-cabal/mock) is also available if you need to stub out some behavior.`mock`can be combined with`unittest`and`pytest`. Here’s a quick usage example:

```
from mock import Mock

mock = Mock()
mock.method(1, 2, 3)
mock.method.assert_called_with('this should break')Code language: Python (python)
```
1. [hypothesis](http://hypothesis.works/) is available for property-based testing in Python. Calling`test_decode_inverts_encode()`fires up Hypothesis and tries to find an input that breaks your code. You can read more about it on their website, but here’s a stubbed example of how you might test that an encoding and decoding function both work:

```
from hypothesis import given
from hypothesis.strategies import text

def encode(string):
    # return encoded string

def decode(string):
    # return decoded string

@given(text())
def test_decode_inverts_encode(s):
    assert decode(encode(s)) == s

test_decode_inverts_encode()Code language: Python (python)
```

## Need a better way to interview candidates?

[Request a demo](https://coderpad.io/sales/)
