> For the complete documentation index, see [llms.txt](https://bc.rocketacademy.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bc.rocketacademy.co/algorithms/a.6-python.md).

# A.7: Python

## Learning Objectives

1. Python is more commonly used than JavaScript for data and algorithm-related work due to its built-in data manipulation libraries and simpler syntax
2. Learn basic Python syntax to be able to use Python for algorithm problems that are easier solved with Python's built-in libraries, such as algorithms involving queues and heaps

## Introduction

Python is commonly used in data and algorithm-related work due to its built-in data manipulation libraries and simpler syntax. Luckily, Python is conceptually very similar to JavaScript, and most translations from Python to JavaScript and vice versa are purely syntactical translations.

This submodule aims to help us learn Python through exercises to solve algorithm problems that are easier solved with Python, such as algorithms involving queues and heaps.

## Python Quirks

1. Python variables adhere to [function scope](https://www.w3schools.com/python/python_scope.asp), which means all local variables are accessible within the function in which they are declared. This is different from the [block scope](https://dev.to/sandy8111112004/javascript-introduction-to-scope-function-scope-block-scope-d11#:~:text=A%20block%20scope%20is%20the,only%20within%20the%20corresponding%20block.) that applies to `let` and `const` vars in JavaScript.
2. Python `==` works like JS `===`, in that both operators compare both value and data type.

## Exercises

The following are a collection of concise exercises from [learnpython.org](https://learnpython.org) (powered by [datacamp.com](https://datacamp.com)) that we believe will be helpful in learning Python for algorithms.

1. [Hello, World!](https://www.learnpython.org/en/Hello%2C_World!)
2. [Variables and Types](https://www.learnpython.org/en/Variables_and_Types)
3. [Lists](https://www.learnpython.org/en/Lists)
4. [Basic Operators](https://www.learnpython.org/en/Basic_Operators)
5. [String Formatting](https://www.learnpython.org/en/String_Formatting) (Here's a [nice article on String Interpolation](https://www.programiz.com/python-programming/string-interpolation))
6. [Basic String Operations](https://www.learnpython.org/en/Basic_String_Operations)
7. [Conditions](https://www.learnpython.org/en/Conditions)
8. [Loops](https://www.learnpython.org/en/Loops)
9. [Functions](https://www.learnpython.org/en/Functions)
10. [Classes and Objects](https://www.learnpython.org/en/Classes_and_Objects)
11. [Dictionaries](https://www.learnpython.org/en/Dictionaries)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://bc.rocketacademy.co/algorithms/a.6-python.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
