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]
Object-Oriented Programming
- class nanograz.OOP.car.Car(model: str = '')[source]
Bases:
objectA 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:
- 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:
CarRepresents 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:
objectRepresents 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