Technologische_Grundlagen/course/python/.ipynb_checkpoints/05-classes-checkpoint.ipynb

112 lines
2.3 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "bcdc32a0-9b80-472b-a7a6-eda570fb8b86",
"metadata": {},
"source": [
"### classes"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "03fc3fad-4c9a-4864-8596-c8e9a383fe4e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"orange\n"
]
}
],
"source": [
"class BauplanKatzenKlasse():\n",
" \"\"\" Klasse für das Erstellen von Katzen \"\"\"\n",
"\n",
" def __init__(self, rufname, farbe, alter):\n",
" self.rufname = rufname\n",
" self.farbe = farbe\n",
" self.alter = alter\n",
" self.schlafdauer = 0\n",
" \n",
" def miauzen(self,amount=1):\n",
" out = \"mia\"\n",
" for i in range(amount):\n",
" out = out + \"u\"\n",
" print(out)\n",
"\n",
"katze_sammy = BauplanKatzenKlasse(\"Sammy\", \"orange\", 3)\n",
"print(katze_sammy.farbe)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "d259947e-1b01-4826-be6b-11909c32bd80",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"miau\n"
]
}
],
"source": [
"katze_sammy.miauzen()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e8a7cff4-b60f-48c8-9c1e-8f209516f992",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"miauuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n"
]
}
],
"source": [
"katze_sammy.miauzen(amount=100)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "caef4f55-b746-457f-9a88-a6e4c47a56f6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}