NBA_01_Datenstrukturen¶
(c) 2024 Technische Hochschule Augsburg - Fakultät für Informatik - Prof.Dr.Nik Klever - Impressum
Variablen¶
In [1]:
var = 12
In [2]:
var + 3.1415
Out[2]:
15.1415
In [3]:
print(var)
12
Einfache Datentypen¶
Integer, Float, Complex¶
In [4]:
var = 3.1415
In [5]:
type(var)
Out[5]:
float
In [6]:
var = 12
In [7]:
type(var)
Out[7]:
int
In [8]:
bin(var)
Out[8]:
'0b1100'
In [9]:
oct(var)
Out[9]:
'0o14'
In [10]:
hex(var)
Out[10]:
'0xc'
Character¶
In [14]:
var = 'c'
In [15]:
type(var)
Out[15]:
str
In [16]:
ord(var)
Out[16]:
99
In [17]:
hex(ord(var))
Out[17]:
'0x63'
Zusammengesetzte Datentypen¶
Sequenzen: Tupel, Strings, Listen¶
In [18]:
var = "abcdef"
In [19]:
var[0:3]
Out[19]:
'abc'
In [20]:
var[0]
Out[20]:
'a'
In [21]:
var[2]
Out[21]:
'c'
In [22]:
var[-3:-1]
Out[22]:
'de'
In [23]:
var[-3:]
Out[23]:
'def'
In [24]:
var[-1]
Out[24]:
'f'
In [25]:
var[-3]
Out[25]:
'd'
Tupel - nicht veränderlich¶
In [26]:
var = (1, 3.1415, 'abc')
In [27]:
var[1]
Out[27]:
3.1415
In [28]:
var[2] = 'def'
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-28-3eeb37ece5b4> in <module>() ----> 1 var[2] = 'def' TypeError: 'tuple' object does not support item assignment
Strings - nicht veränderlich¶
Listen - veränderlich¶
In [29]:
var = [1, 3.1415, 'abc']
In [30]:
var[2] = 'def'
In [31]:
var
Out[31]:
[1, 3.1415, 'def']
In [32]:
type(var)
Out[32]:
list
In [33]:
var = (1, 3.1415, 'abc')
In [34]:
type(var)
Out[34]:
tuple
Set¶
In [35]:
var = {1,2,3,'a','b','c'}
In [36]:
type(var)
Out[36]:
set
Dictionary¶
In [37]:
var = {'ort':'nördlingen','strasse':'emil-eigner-str','hausnr':'1'}
In [38]:
type(var)
Out[38]:
dict
In [39]:
var['ort']
Out[39]:
'nördlingen'
Einsatz welcher Datenstruktur¶
Liste vs. Dictionary¶
Liste¶
- zeitliche Ordnung einer Datenstruktur (z.B. Log-Dateien, Messdaten, etc.)
- alphabetische Ordnung einer Datenstruktur (z.B. Adressbuch, Kundendaten, etc.)
Dictionary¶
- Eigenschaften in der Datenstruktur vorhanden (z.B. Adressen, Kunden, Produktdaten, etc.)