Python Next-Level: Objekte in Datenstrukturen für Fortgeschrittene 🐍
Entdecke, wie du in Python komplexe Objekte in Datenstrukturen integrierst und deine Programmierung auf das nächste Level bringst. Perfekt für fortgeschrittene Entwickler!

Sara-Liya
161 views • Dec 16, 2022

About this video
Python Next-Level objektorientierte Programmierung - Objekte in Datenstrukturen
Thema:
Ich möchte dir heute mal eine Möglichkeit zeigen, wie man Objekte in Datenstrukturen, wie beispielsweise einer Liste aufnehmen kann, um somit das Programm einfacher und übersichtlich zu gestalten.
Code (in dieser Lektion):
class Smartphone:
'''Das Smartphones Preise mit Rabattaktion.'''
rabatt = 0.85
def __init__(self, phone_name, system, preis, dual_sim=False):
self.phone_name = phone_name
self.system = system
self.preis = preis
self.dual_sim = dual_sim
Smartphone.rabatt = 0.70
# self.rabattierte_preis =(Smartphone.rabatt * self.preis)
# print(self.rabattierte_preis)
# p1 = Smartphone("Apple iPhone 13 Pro", "iOS 15", 1499, True)
# p2 = Smartphone("Samsung Galaxy S22 Ultra", "Android 12", 990)
smartphones = [Smartphone("Apple iPhone 13 Pro", "iOS 15", 1499, True),
Smartphone("Samsung Galaxy S22 Ultra", "Android 12", 990),
Smartphone("Xiaomi 12 5G 256GB", "Android", 530)
]
# So greifen wir auf einzelne Werte zu:
# print(smartphones[0].phone_name)
# print(smartphones[1].phone_name)
# print(id(smartphones[0]))
# print(id(smartphones[1]))
# print(id(smartphones[2]))
for objekte in smartphones:
print(objekte.phone_name, objekte.preis, objekte.dual_sim, sep=' - ')
# print(p1.phone_name, p1.system, p1.preis, p1.dual_sim)
# print(p2.phone_name, p2.system, p2.preis, p2.dual_sim)
#
# # print(Smartphone.__dict__)
# # print(p1.__dict__)
#
# print(Smartphone.rabatt)
# print(p1.rabatt)
Thema:
Ich möchte dir heute mal eine Möglichkeit zeigen, wie man Objekte in Datenstrukturen, wie beispielsweise einer Liste aufnehmen kann, um somit das Programm einfacher und übersichtlich zu gestalten.
Code (in dieser Lektion):
class Smartphone:
'''Das Smartphones Preise mit Rabattaktion.'''
rabatt = 0.85
def __init__(self, phone_name, system, preis, dual_sim=False):
self.phone_name = phone_name
self.system = system
self.preis = preis
self.dual_sim = dual_sim
Smartphone.rabatt = 0.70
# self.rabattierte_preis =(Smartphone.rabatt * self.preis)
# print(self.rabattierte_preis)
# p1 = Smartphone("Apple iPhone 13 Pro", "iOS 15", 1499, True)
# p2 = Smartphone("Samsung Galaxy S22 Ultra", "Android 12", 990)
smartphones = [Smartphone("Apple iPhone 13 Pro", "iOS 15", 1499, True),
Smartphone("Samsung Galaxy S22 Ultra", "Android 12", 990),
Smartphone("Xiaomi 12 5G 256GB", "Android", 530)
]
# So greifen wir auf einzelne Werte zu:
# print(smartphones[0].phone_name)
# print(smartphones[1].phone_name)
# print(id(smartphones[0]))
# print(id(smartphones[1]))
# print(id(smartphones[2]))
for objekte in smartphones:
print(objekte.phone_name, objekte.preis, objekte.dual_sim, sep=' - ')
# print(p1.phone_name, p1.system, p1.preis, p1.dual_sim)
# print(p2.phone_name, p2.system, p2.preis, p2.dual_sim)
#
# # print(Smartphone.__dict__)
# # print(p1.__dict__)
#
# print(Smartphone.rabatt)
# print(p1.rabatt)
Tags and Topics
Browse our collection to discover more content in these categories.
Video Information
Views
161
Likes
7
Duration
15:59
Published
Dec 16, 2022
Related Trending Topics
LIVE TRENDSRelated trending topics. Click any trend to explore more videos.
Trending Now