ABSTRACT

Python is the “Swiss Army Knife” of modern science. It is versatile, beginner-friendly programming language used for everything from data analysis and scientific research to automation and web development. Its simple and readable syntax makes it the perfect tool for learning fundamental programming concepts.

1. Running Python Code

There are three primary ways to interact with Python:

Option 1: Interavtive Shell

Best for quick calculations or testing single lines of code. Open your terminal and type python3.

>>> 5 + 3
8
>>> print("Hello!")
Hello!

*Press Ctrl+Dor type exit() to leave.

Option 2: Python Scripts (.py)

For actual projects, you write a code in a file and run it all at once.

  1. Create hello.py
  2. Run it via terminal: python3 hello.py

Option 3: Python Notebooks

Python notebooks (.ipynb) allow you to write code blocks and interact with the results at the same time, maintaining a global variable storage for the session. They also allow to combine Python code cells with Markdown explanation cells. This topic is handled in AB Jupyter Notebooks

2. Variables and Data Types

A Variable is a named container for storing data. Python identifies the type of the data automatically, unlike C++ for example.

TypeDescriptionExample
String (str)Text dataname = "Alice", friend = 'Bob'
 Integer (int) Whole Numbers age = 25
Float (float)Decimal numberspi = 3.14
Boolean (bool) Logic is_ready = True, repeat = False

3. Operations

Arithmetics

Python handles math naturally using standard operators:

  • +, -, *, / (Standard math)
  • // (Floor division: 10 // 3 = 3)
  • ** (Exponentiation: 2 ** 3 = 8)
  • % (Modulo: gives the remainder)

Strings

You can combine strings with + or use f-strings for easy formatting:

name = "Bob"
print(f"Hello, {name}!") # Output: Hello, Bob!

4. Control Flow

If/Else Statements

Use logic to decide which code to run.

age = 20
if age >= 18:
    print("Adult")
else:
    print("Minor")

Loops

  • While Loop: Runs as long as a condition is true.
  • For Loop: Iterates over a sequence (like a list or a range of numbers).
for i in range(3):
    print(f"Counting: {i}") # Prints 0, 1, 2

5. Collections: Lists and Dictionaries

Lists (Ordered)

Use square brackets [] to store a sequence of items.

  • Access items by index: fruits[0] is the first item.
  • Add items: fruits.append("mango").

Dictionaries (Key-Value)

Use curly braces {} to store data in pairs.

student = {"name": "Alice", "grade": "A"}
print(student["name"]) # Alice

6. Functions

Functions are reusable “recipes” for code. You define them once and call them whenever needed.

def multiply(a, b):
    return a * b
 
result = multiply(10, 5) # result is 50

7. Error Handling

Instead of letting your program crash when it hits an error, use try and except blocks to handle issues gracefully. This is great when working with unphysical combinations in parameter spaces.

try:
    x = 1 / 0
except ZeroDivisionError:
    print("You can't divide by zero!")

SUCCESS

You now have the fundamenta building blocks of Pythona and have completed all tech foundations onboarding tutorials. You may now proceed to the advance tutorials or you can begin actually contributing to CAPIBARA’s codebase. Remember these 3 central ideas:

  1. Python is an extremely wide useage language, there are tons of tutorials, guidelines and solution on the internet. Make a good use of them, but don’t try to digest everything.
  2. There are Python libraries for everything. Most important Python libraries (NumPy, Matplotlib, SciPy, etc) have extensive and supported documentation.
  3. It probably happens that you are not the first one encoutering an issue: ask other group members directly or wrtite on the help desk discussion.