<jupyter_start><jupyter_text>Objects and operationsPython is a a popular scientific programming language and is regularly used both inside and outside of academia. In this course, we hope to introduce programming in Python before going on to show some applications of the langauge in a computational chemistry setting. The vision for the course structure is something a bit like that shown in {numref}`Figure {number} `.This means that we need to start by introducing some Python.```{figure} ./images/content.png---scale: 35%name: contentalt: A plot of the chemistry content increasing linearly over time while the programming content decreases at the same rate.---What you can expect to be learning over time.```Python consists of objects of *types*, where the type of an object may determine the operations that may be performed on it. For example, let us consider a simple numerical type, the integer.<jupyter_code>4<jupyter_output><empty_output><jupyter_text>The object in the above cell is an integer (or `int`), we can get the type of this object with the `type()` function.<jupyter_code>type(4)<jupyter_output><empty_output><jupyter_text>Since this object is numerical in nature, we can imagine using it in mathematical operations.<jupyter_code>4 + 4
type(4 + 4)<jupyter_output><empty_output><jupyter_text>Above, we have used a mathematical operation between two integers to create a new integer object.Integers are whole numbers, numbers that do not have a decimal point (e.g. 1, 2, 3, 4, 5, 6, etc.). However, Python is also capable of handling floating point (or `float`) type numbers, where there is a decimal point.<jupyter_code>3.14
type(3.14)<jupyter_output><empty_output><jupyter_text>These floating point numbers can also be used in mathematical operations.<jupyter_code>1.1 + 2.2<jupyter_output><empty_output><jupyter_text>Notice, above the result of `1.1 + 2.2` is `3.3000000000000003`, which isn't exactly correct. This results from a problem of the way that floating point numbers are stored in the computer's memory, known as [floating point arthimetic](https://floating-point-gui.de). You may see examples of this throughout this course, typically the error in the result is **very** small. In the example above the result is off by less than $1\times 10^{-15}$ of a percent. Therefore, it is unlikely that this should impact the computation that you perform in this course. However, it is important to be aware of this problem.> **Exercise** : In a Jupyter Notebook on your JupyterHub instance, consider the difference between `1`, `1.` and `1.0` as interpreted by Python.> Use the `type()` function to determine the type of each of the values.> From this, explain (in a Markdown cell in the same notebook) the importance of the decimal point in teh definition of numerical types in Python.Textual information in Python is stored as in strings (or `str`), such as that shown below.<jupyter_code>"Hello World!"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07427413909520594, 'fraction_numerical': 0.01823092505064146, 'mean_word_length': 5.358369098712446, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 28, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '293719', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 822, 'n_tokens_neox': 772, 'n_words': 408, 'path': 'CH40208/python_basics/objects_and_operations.ipynb', 'repo_name': 'pythoninchemistry/ch40208', 'size': '2962'}