Documentation

Example

nanograz.example.custom_match(text: str, regex: str) list[str][source]

Custom regex match function that finds all occurrences of a pattern in the given text.

Parameters:
  • text (str) – The text to search within.

  • pattern (str) – The regex pattern to search for.

Returns:

A list of all matches found in the text.

Return type:

list[str]

nanograz.example.foo(x: int, y: str = 'foo')[source]

Demo function to demonstrate type annotations.

Parameters:
  • x (int) – An integer input.

  • y (str, optional) – A string input. Defaults to “foo”.

Returns:

int

nanograz.example.square(x: int | float) int | float[source]

Calculates the square of a number.

Parameters:

x (int|float) – The number to be squared.

Returns:

The square of the input number.

Return type:

int|float

Object-Oriented Programming

class nanograz.OOP.car.Car(model: str = '')[source]

Bases: object

A class representing a car.

model

The model name of the car.

Type:

str

count: int = 0
drive(speed: float)[source]

Drives the car at the specified speed.

Parameters:

speed (float) – The speed at which to drive the car, in kilometers per hour (km/h).

classmethod from_brand(brand: str) Car[source]

Creates a Car instance based on the brand name.

Parameters:

brand (str) – The brand of the car.

Returns:

An instance of Car with a model name corresponding to the brand.

Return type:

Car

models_by_brand = {'Ford': 'Ford Focus', 'Toyota': 'Toyota Corolla', 'VW': 'VW Golf'}
static mph_to_kmh(speed_mph: float) float[source]

Convert a speed from miles per hour (mph) to kilometers per hour (km/h).

Parameters:

speed_mph (float) – Speed in miles per hour.

Returns:

Equivalent speed in kilometers per hour. Conversion uses the factor 1 mile = 1.60934 kilometers.

Return type:

float

class nanograz.OOP.car.Truck(capacity: int, model: str = '')[source]

Bases: Car

Represents a truck, which is a type of car with additional cargo capacity.

capacity

The cargo capacity of the truck.

Type:

int

class nanograz.OOP.vector.Vector(x: float, y: float)[source]

Bases: object

Represents a 2-dimensional vector with x and y components.

Parameters:
  • x (float) – The x component of the vector.

  • y (float) – The y component of the vector.

x

The x component of the vector.

Type:

float

y

The y component of the vector.

Type:

float

__add__(other)[source]

Adds this vector to another vector.

__repr__()[source]

Returns a string representation of the vector.