commit message from python script
This commit is contained in:
18
Lehrer/pythonkurs/Montag/contains1
Executable file
18
Lehrer/pythonkurs/Montag/contains1
Executable file
@@ -0,0 +1,18 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Removes a key-value pair"
|
||||
|
||||
print("Kommt Wort 'value' im String vor?", 'value' in string)
|
||||
print("Kommt Wort 'value' im String vor?", "value" in string)
|
||||
|
||||
mlist = ['Quatsch', 'Liste']
|
||||
|
||||
print("Kommt Wert 'Quatsch' in der Liste vor?", 'Quatsch' in mlist)
|
||||
print("Kommt Wert 'Quatsch' in der Liste vor?", "Quatsch" in mlist)
|
||||
|
||||
mydict = {'hostname': 'notebook14', 'address': '192.168.1.214', 'maker': 'Lenovo', 'type': 'T530', 'ramsize': 16, 'ssd': True}
|
||||
|
||||
print("Kommt Key 'hostname' im Dictionary vor?", 'hostname' in mydict)
|
||||
print("Kommt Key 'hostname' im Dictionary vor?", "hostname" in mydict)
|
||||
|
||||
|
||||
24
Lehrer/pythonkurs/Montag/contains2
Executable file
24
Lehrer/pythonkurs/Montag/contains2
Executable file
@@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Removes a key-value pair"
|
||||
|
||||
print("Kommt Wort 'value' im String vor?", 'value' in string)
|
||||
print("Kommt Wort 'value' im String vor?", "value" in string)
|
||||
|
||||
mlist = ['Quatsch', 'Liste']
|
||||
|
||||
print("Kommt Wert 'Quatsch' in der Liste vor?", 'Quatsch' in mlist)
|
||||
print("Kommt Wert 'Quatsch' in der Liste vor?", "Quatsch" in mlist)
|
||||
|
||||
mydict = {'hostname': 'notebook14',
|
||||
'address': '192.168.1.214',
|
||||
'maker': 'Lenovo',
|
||||
'type': 'T530',
|
||||
'ramsize': 16,
|
||||
'ssd': True,
|
||||
}
|
||||
|
||||
print("Kommt Key 'hostname' im Dictionary vor?", 'hostname' in mydict)
|
||||
print("Kommt Key 'hostname' im Dictionary vor?", "hostname" in mydict)
|
||||
|
||||
|
||||
14
Lehrer/pythonkurs/Montag/dict1
Executable file
14
Lehrer/pythonkurs/Montag/dict1
Executable file
@@ -0,0 +1,14 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {}
|
||||
print("Leeres Dictionary:", mydict, "mit Laenge:", len(mydict))
|
||||
|
||||
# Legt ggf. das Key-Value-Paar neu an
|
||||
mydict['hostname'] = "notebook14"
|
||||
mydict['address'] = '192.168.1.214'
|
||||
mydict['maker'] = 'Lenovo'
|
||||
mydict['type'] = 'T530'
|
||||
mydict['ramsize'] = 16
|
||||
mydict['ssd'] = True
|
||||
|
||||
print("Nicht-Leeres Dictionary:", mydict, "mit Laenge:", len(mydict))
|
||||
20
Lehrer/pythonkurs/Montag/dict2
Executable file
20
Lehrer/pythonkurs/Montag/dict2
Executable file
@@ -0,0 +1,20 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {}
|
||||
print("Leeres Dictionary:", mydict, "mit Laenge:", len(mydict))
|
||||
|
||||
# Legt ggf. das Key-Value-Paar neu an
|
||||
mydict['hostname'] = "notebook14"
|
||||
mydict['address'] = '192.168.1.214'
|
||||
mydict['maker'] = 'Lenovo'
|
||||
mydict['type'] = 'T530'
|
||||
mydict['ramsize'] = 16
|
||||
mydict['ssd'] = True
|
||||
|
||||
for key in mydict.keys():
|
||||
print(key, '=', mydict[key])
|
||||
|
||||
print("-"*50)
|
||||
|
||||
for value in mydict.values():
|
||||
print(value)
|
||||
21
Lehrer/pythonkurs/Montag/dict3
Executable file
21
Lehrer/pythonkurs/Montag/dict3
Executable file
@@ -0,0 +1,21 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {}
|
||||
|
||||
# Legt ggf. das Key-Value-Paar neu an
|
||||
mydict['hostname'] = "notebook14"
|
||||
mydict['address'] = '192.168.1.214'
|
||||
mydict['maker'] = 'Lenovo'
|
||||
mydict['type'] = 'T530'
|
||||
mydict['ramsize'] = 16
|
||||
mydict['ssd'] = True
|
||||
|
||||
# Iteration ueber Dictionary selbst iteriert ueber die Keys
|
||||
for key in mydict:
|
||||
print(key, '=', mydict[key])
|
||||
|
||||
print("-"*50)
|
||||
|
||||
# Gleichzeitige Iteration ueber Key und Value
|
||||
for key, value in mydict.items():
|
||||
print(key, '=', value)
|
||||
24
Lehrer/pythonkurs/Montag/dict4
Executable file
24
Lehrer/pythonkurs/Montag/dict4
Executable file
@@ -0,0 +1,24 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {}
|
||||
|
||||
key_dict = {'eins': 1}
|
||||
key_list = [1, 2, 3]
|
||||
|
||||
# Achtung: Nicht-hashbare Typen
|
||||
#mydict[key_dict] = 'foo'
|
||||
#mydict[key_list] = 'bar'
|
||||
|
||||
mydict[True] = 'True'
|
||||
mydict[False] = 'False'
|
||||
mydict[None] = 'None'
|
||||
|
||||
print(mydict)
|
||||
|
||||
# Achtung: Ueberschreibt die Werte von mydict[True] und mydict[False]
|
||||
mydict[0] = '0'
|
||||
mydict[1] = '1'
|
||||
print(mydict)
|
||||
|
||||
print(0 == False)
|
||||
print(1 == True)
|
||||
28
Lehrer/pythonkurs/Montag/dict5
Executable file
28
Lehrer/pythonkurs/Montag/dict5
Executable file
@@ -0,0 +1,28 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {}
|
||||
|
||||
# Legt ggf. das Key-Value-Paar neu an
|
||||
mydict['hostname'] = "notebook14"
|
||||
mydict['address'] = '192.168.1.214'
|
||||
mydict['maker'] = 'Lenovo'
|
||||
mydict['type'] = 'T530'
|
||||
mydict['ramsize'] = 16
|
||||
mydict['ssd'] = True
|
||||
|
||||
# Iteration ueber Dictionary selbst iteriert ueber die Keys
|
||||
for key in mydict:
|
||||
print(key, '=', mydict[key])
|
||||
|
||||
print("-"*50)
|
||||
|
||||
# Gleichzeitige Iteration ueber Key und Value
|
||||
for key, value in mydict.items():
|
||||
print(key, '=', value)
|
||||
|
||||
print("-"*50)
|
||||
|
||||
# Achtung: Python liefert KeyError, falls der Key unbekannt
|
||||
# print(mydict['year'])
|
||||
print(mydict.get('year'))
|
||||
print(mydict.get('year', 2010))
|
||||
22
Lehrer/pythonkurs/Montag/dict6
Executable file
22
Lehrer/pythonkurs/Montag/dict6
Executable file
@@ -0,0 +1,22 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {}
|
||||
|
||||
# Legt ggf. das Key-Value-Paar neu an
|
||||
mydict['hostname'] = "notebook14"
|
||||
mydict['address'] = '192.168.1.214'
|
||||
mydict['maker'] = 'Lenovo'
|
||||
mydict['type'] = 'T530'
|
||||
mydict['ramsize'] = 16
|
||||
mydict['ssd'] = True
|
||||
|
||||
print(mydict)
|
||||
|
||||
value = mydict.pop('address')
|
||||
|
||||
print(mydict)
|
||||
|
||||
key, value = mydict.popitem()
|
||||
print("Geloeschter Key:", key)
|
||||
|
||||
print(mydict)
|
||||
4
Lehrer/pythonkurs/Montag/hello_world
Executable file
4
Lehrer/pythonkurs/Montag/hello_world
Executable file
@@ -0,0 +1,4 @@
|
||||
#! /usr/bin/env python3
|
||||
#! /usr/bin/python3
|
||||
|
||||
print("Hello World!")
|
||||
3
Lehrer/pythonkurs/Montag/hello_world2
Executable file
3
Lehrer/pythonkurs/Montag/hello_world2
Executable file
@@ -0,0 +1,3 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
print("Hello", "World!")
|
||||
6
Lehrer/pythonkurs/Montag/hello_world3
Executable file
6
Lehrer/pythonkurs/Montag/hello_world3
Executable file
@@ -0,0 +1,6 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
text = "Hallo" + ' ' + "World" + '!'
|
||||
print(text)
|
||||
|
||||
print("Länge der Zeichenkette:", len(text))
|
||||
8
Lehrer/pythonkurs/Montag/hello_world4
Executable file
8
Lehrer/pythonkurs/Montag/hello_world4
Executable file
@@ -0,0 +1,8 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
# + entspricht String-Concatenation
|
||||
text = "Hallo" + ' ' + "World" + '!'
|
||||
print(text)
|
||||
|
||||
# * entspricht String-Repeat
|
||||
print('=' * len(text))
|
||||
29
Lehrer/pythonkurs/Montag/if
Executable file
29
Lehrer/pythonkurs/Montag/if
Executable file
@@ -0,0 +1,29 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mydict = {'hostname': 'notebook14',
|
||||
'address': '192.168.1.214',
|
||||
'maker': 'Lenovo',
|
||||
'type': 'T530',
|
||||
'ramsize': 16,
|
||||
'ssd': True,
|
||||
}
|
||||
|
||||
if 'maker' in mydict:
|
||||
print("Key maker wird verwendet")
|
||||
|
||||
if 'maker' in mydict and 'type' in mydict:
|
||||
if mydict['maker'] == 'Lenovo' and mydict['type'].startswith('T'):
|
||||
print("Thinkpad gefunden")
|
||||
|
||||
if 'maker' in mydict and 'type' in mydict and \
|
||||
mydict['maker'] == 'Lenovo' and \
|
||||
mydict['type'].startswith('T'):
|
||||
print("Thinkpad gefunden")
|
||||
|
||||
if 'maker' in mydict and mydict['maker'] == 'Lenovo' and \
|
||||
'type' in mydict and mydict['type'].startswith('T'):
|
||||
print("Thinkpad gefunden")
|
||||
|
||||
if ('maker' in mydict and mydict['maker'] == 'Lenovo' and
|
||||
'type' in mydict and mydict['type'].startswith('T')):
|
||||
print("Thinkpad gefunden")
|
||||
17
Lehrer/pythonkurs/Montag/list1
Executable file
17
Lehrer/pythonkurs/Montag/list1
Executable file
@@ -0,0 +1,17 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mylist = []
|
||||
print("Leere Liste:", mylist)
|
||||
print("Laenge der Liste:", len(mylist))
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 11]
|
||||
print(numbers)
|
||||
print("Laenge der Liste:", len(numbers))
|
||||
|
||||
print("1. Element:", numbers[0])
|
||||
print("Letztes Element:", numbers[len(numbers)-1])
|
||||
print("Letztes Element:", numbers[-1])
|
||||
|
||||
# Explizite Aenderung des Wertes
|
||||
numbers[-1] = 55
|
||||
print("Neues letztes Element:", numbers[-1])
|
||||
16
Lehrer/pythonkurs/Montag/list2
Executable file
16
Lehrer/pythonkurs/Montag/list2
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 13]
|
||||
print(numbers)
|
||||
print("Laenge der Liste:", len(numbers))
|
||||
|
||||
# Zugriff nur innerhalb der vorhandenen Indizes erlaubt
|
||||
# numbers[len(numbers)] = 21
|
||||
|
||||
numbers.append(21)
|
||||
print(numbers)
|
||||
print("Laenge der Liste:", len(numbers))
|
||||
|
||||
numbers.insert(0, 0) # 1. Parameter ist Index, 2. Parameter der Wert
|
||||
print(numbers)
|
||||
print("Laenge der Liste:", len(numbers))
|
||||
8
Lehrer/pythonkurs/Montag/list3
Executable file
8
Lehrer/pythonkurs/Montag/list3
Executable file
@@ -0,0 +1,8 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 13]
|
||||
numbers.append(21)
|
||||
numbers.insert(0, 0) # 1. Parameter ist Index, 2. Parameter der Wert
|
||||
|
||||
for value in numbers:
|
||||
print(value)
|
||||
20
Lehrer/pythonkurs/Montag/list4
Executable file
20
Lehrer/pythonkurs/Montag/list4
Executable file
@@ -0,0 +1,20 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 13]
|
||||
numbers.append(21)
|
||||
numbers.insert(0, 0) # 1. Parameter ist Index, 2. Parameter der Wert
|
||||
|
||||
# Slice =~ Start-Index und Stop-Index
|
||||
number_slice1 = numbers[0:3]
|
||||
number_slice2 = numbers[3:6]
|
||||
number_slice3 = numbers[-4:-1]
|
||||
|
||||
print(number_slice1)
|
||||
print(number_slice2)
|
||||
print(number_slice3)
|
||||
|
||||
# Sonderfall: Start-Index = 0
|
||||
print(numbers[:-3])
|
||||
|
||||
# Sonderfall: Stop-Index = Laenge
|
||||
print(numbers[3:])
|
||||
9
Lehrer/pythonkurs/Montag/list5
Executable file
9
Lehrer/pythonkurs/Montag/list5
Executable file
@@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 13]
|
||||
numbers.append(21)
|
||||
numbers.insert(0, 0) # 1. Parameter ist Index, 2. Parameter der Wert
|
||||
|
||||
print(numbers[:-4])
|
||||
for value in numbers[:-4]:
|
||||
print(value)
|
||||
15
Lehrer/pythonkurs/Montag/list6
Executable file
15
Lehrer/pythonkurs/Montag/list6
Executable file
@@ -0,0 +1,15 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 13]
|
||||
numbers.append(21)
|
||||
numbers.insert(0, 0) # 1. Parameter ist Index, 2. Parameter der Wert
|
||||
|
||||
# Achtung: Nur die Referenz wird kopiert
|
||||
kopie = numbers
|
||||
|
||||
kopie[0] = -1
|
||||
kopie[1] = -2
|
||||
kopie[2] = -3
|
||||
|
||||
print(numbers)
|
||||
print(kopie)
|
||||
16
Lehrer/pythonkurs/Montag/list7
Executable file
16
Lehrer/pythonkurs/Montag/list7
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
numbers = [1, 1, 2, 3, 5, 8, 13]
|
||||
numbers.append(21)
|
||||
numbers.insert(0, 0) # 1. Parameter ist Index, 2. Parameter der Wert
|
||||
|
||||
# Hier echte Kopie erzeugen
|
||||
kopie = numbers[:]
|
||||
#kopie = numbers.copy()
|
||||
|
||||
kopie[0] = -1
|
||||
kopie[1] = -2
|
||||
kopie[2] = -3
|
||||
|
||||
print(numbers)
|
||||
print(kopie)
|
||||
6
Lehrer/pythonkurs/Montag/list8
Executable file
6
Lehrer/pythonkurs/Montag/list8
Executable file
@@ -0,0 +1,6 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
wortliste = ['Das', 'ist', 'ein', 'Satz', 'mit', 'X', 'gewesen']
|
||||
|
||||
for wort in wortliste[:-1]:
|
||||
print(wort)
|
||||
9
Lehrer/pythonkurs/Montag/list9
Executable file
9
Lehrer/pythonkurs/Montag/list9
Executable file
@@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mlist = ['Quatsch', 'Liste']
|
||||
|
||||
# Nur Objekte sind als Element einer Liste zugelassen
|
||||
mylist = ['Das', 10, 3.14, True, False, None, ['subliste'], [], mlist]
|
||||
|
||||
for value in mylist:
|
||||
print(value)
|
||||
12
Lehrer/pythonkurs/Montag/lista
Executable file
12
Lehrer/pythonkurs/Montag/lista
Executable file
@@ -0,0 +1,12 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
mlist = ['Quatsch', 'Liste']
|
||||
print(mlist)
|
||||
|
||||
mlist.remove('Quatsch')
|
||||
print(mlist)
|
||||
|
||||
# Ohne Parameter wird das letzte Element entfernt
|
||||
# Mit Parameter das des angegebenen Indizes
|
||||
elem = mlist.pop()
|
||||
print(mlist)
|
||||
16
Lehrer/pythonkurs/Montag/print1
Executable file
16
Lehrer/pythonkurs/Montag/print1
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Linuxhotel, Essen"
|
||||
integer = 13
|
||||
double = 3.1415
|
||||
|
||||
print(string, integer, double)
|
||||
|
||||
# can only concatenate str (not "int") to str
|
||||
# Daher muss die Zahl zuerst in einen String konvertiert werden
|
||||
text = string + ' ' + str(integer)
|
||||
text = text + ' ' + str(double)
|
||||
|
||||
# Falls die nächste Zeile eingerueckt wird, kann Python die Datei
|
||||
# nicht mehr compilieren, und erzeugt einen Syntax-Fehler
|
||||
print(text)
|
||||
19
Lehrer/pythonkurs/Montag/print1_version2.x
Executable file
19
Lehrer/pythonkurs/Montag/print1_version2.x
Executable file
@@ -0,0 +1,19 @@
|
||||
#! /usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
# Compiler-Anweisung zum Character-Set muss in 1. oder 2. Zeile stehen
|
||||
# Im Fall von UTF-8 nur fuer Python 2.x erforderlich
|
||||
|
||||
string = "Linuxhotel, Essen"
|
||||
integer = 13
|
||||
double = 3.1415
|
||||
|
||||
print(string, integer, double)
|
||||
|
||||
# can only concatenate str (not "int") to str
|
||||
# Daher muss die Zahl zuerst in einen String konvertiert werden
|
||||
text = string + ' ' + str(integer)
|
||||
text = text + ' ' + str(double)
|
||||
|
||||
# Falls die nächste Zeile eingerueckt wird, kann Python die Datei
|
||||
# nicht mehr compilieren, und erzeugt einen Syntax-Fehler
|
||||
print(text)
|
||||
19
Lehrer/pythonkurs/Montag/print2
Executable file
19
Lehrer/pythonkurs/Montag/print2
Executable file
@@ -0,0 +1,19 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Linuxhotel, Essen"
|
||||
integer = 13
|
||||
double = 3.1415
|
||||
null = None # expliziter Nicht-Wert, aka NULL, 0x00, NIL
|
||||
empty_string = ''
|
||||
|
||||
print(string, integer, double)
|
||||
|
||||
# can only concatenate str (not "int") to str
|
||||
# Daher muss die Zahl zuerst in einen String konvertiert werden
|
||||
text = string + ' ' + str(integer)
|
||||
text += ' ' + str(double)
|
||||
|
||||
# Falls die nächste Zeile eingerueckt wird, kann Python die Datei
|
||||
# nicht mehr compilieren, und erzeugt einen Syntax-Fehler
|
||||
print(text)
|
||||
print(null)
|
||||
16
Lehrer/pythonkurs/Montag/schachbrett1
Executable file
16
Lehrer/pythonkurs/Montag/schachbrett1
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
spalten = [ None for col in "12345678" ]
|
||||
# Achtung: Hier wird immer die Referenz auf das Objekt spalten verwendet
|
||||
# zeilen = [spalten for row in "ABCDEFGH"]
|
||||
# Daher besser eine echte Kopie erstellen
|
||||
zeilen = [spalten.copy() for row in "ABCDEFGH"]
|
||||
|
||||
print(zeilen)
|
||||
# Achtung: Falls oben die Referenz verwendet wird, erhaelt man 32 Tuerme
|
||||
zeilen[0][0] = 'Turm'
|
||||
zeilen[0][-1] = 'Turm'
|
||||
zeilen[-1][0] = 'turm'
|
||||
zeilen[-1][-1] = 'turm'
|
||||
print(zeilen)
|
||||
|
||||
14
Lehrer/pythonkurs/Montag/schachbrett2
Executable file
14
Lehrer/pythonkurs/Montag/schachbrett2
Executable file
@@ -0,0 +1,14 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
spalten = [ None for col in "12345678" ]
|
||||
zeilen = [spalten.copy() for row in "ABCDEFGH"]
|
||||
|
||||
zeilen[0][0] = 'Turm'
|
||||
zeilen[0][-1] = 'Turm'
|
||||
zeilen[-1][0] = 'turm'
|
||||
zeilen[-1][-1] = 'turm'
|
||||
|
||||
|
||||
print("Adressen der Spalten-Listen:")
|
||||
for spalte in zeilen:
|
||||
print(id(spalte))
|
||||
16
Lehrer/pythonkurs/Montag/schachbrett3
Executable file
16
Lehrer/pythonkurs/Montag/schachbrett3
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
spalten = [ None for col in "12345678" ]
|
||||
zeilen = [spalten.copy() for row in "ABCDEFGH"]
|
||||
|
||||
zeilen[0][0] = 'Turm'
|
||||
zeilen[0][-1] = 'Turm'
|
||||
zeilen[-1][0] = 'turm'
|
||||
zeilen[-1][-1] = 'turm'
|
||||
|
||||
|
||||
for zeile in zeilen:
|
||||
for zelle in zeile:
|
||||
print(zelle, end=' ')
|
||||
else:
|
||||
print()
|
||||
16
Lehrer/pythonkurs/Montag/schachbrett4
Executable file
16
Lehrer/pythonkurs/Montag/schachbrett4
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
# Alternativ als geschachtelte List Comprehension
|
||||
zeilen = [[ None for col in "12345678" ] for row in "ABCDEFGH"]
|
||||
|
||||
zeilen[0][0] = 'Turm'
|
||||
zeilen[0][-1] = 'Turm'
|
||||
zeilen[-1][0] = 'turm'
|
||||
zeilen[-1][-1] = 'turm'
|
||||
|
||||
|
||||
for zeile in zeilen:
|
||||
for zelle in zeile:
|
||||
print(zelle, end=' ')
|
||||
else:
|
||||
print()
|
||||
9
Lehrer/pythonkurs/Montag/strings1
Executable file
9
Lehrer/pythonkurs/Montag/strings1
Executable file
@@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Das ist kein Satz"
|
||||
|
||||
print(string[:3])
|
||||
print(string[-4:])
|
||||
|
||||
# Strings sind unveraenderlich
|
||||
# string[0] = 'd'
|
||||
13
Lehrer/pythonkurs/Montag/strings2
Executable file
13
Lehrer/pythonkurs/Montag/strings2
Executable file
@@ -0,0 +1,13 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Das ist kein Satz"
|
||||
wortliste = string.split(' ')
|
||||
|
||||
print(wortliste)
|
||||
print(wortliste[:2])
|
||||
|
||||
wortliste[2] = 'ein'
|
||||
print(wortliste)
|
||||
|
||||
string = ' '.join(wortliste)
|
||||
print(string)
|
||||
9
Lehrer/pythonkurs/Montag/strings3
Executable file
9
Lehrer/pythonkurs/Montag/strings3
Executable file
@@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Das ist kein Satz"
|
||||
wortliste = string.split(' ')
|
||||
|
||||
print(wortliste)
|
||||
print(wortliste[-1:])
|
||||
print(wortliste[-1:][0])
|
||||
print(wortliste[-1])
|
||||
7
Lehrer/pythonkurs/Montag/strings4
Executable file
7
Lehrer/pythonkurs/Montag/strings4
Executable file
@@ -0,0 +1,7 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Stringtheorie"
|
||||
|
||||
print(string)
|
||||
for c in string:
|
||||
print(c)
|
||||
27
Lehrer/pythonkurs/Montag/strings5
Executable file
27
Lehrer/pythonkurs/Montag/strings5
Executable file
@@ -0,0 +1,27 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Stringtheorie"
|
||||
|
||||
asciiwerte = []
|
||||
for c in string:
|
||||
asciiwerte.append(ord(c))
|
||||
|
||||
# Diese Schleife als List Comprehension
|
||||
# asciiwerte = [ord(c) for c in string]
|
||||
|
||||
print(asciiwerte)
|
||||
|
||||
# 65 = A, 97 = a
|
||||
# ord('a') - ord('A')
|
||||
asciiwerte[0] = asciiwerte[0] + (97-65)
|
||||
|
||||
# List Comprehension = On-the-Fly-Berechnung ganzer Listen
|
||||
# Kopie von asciiwerte, alternativ zu asciiwerte[:] oder asciiwerte.copy()
|
||||
ascii_list = [value for value in asciiwerte]
|
||||
|
||||
# Neue Liste von Zeichen
|
||||
char_list = [chr(value) for value in asciiwerte]
|
||||
print(char_list)
|
||||
|
||||
ziel_string = ''.join(char_list)
|
||||
print(ziel_string)
|
||||
13
Lehrer/pythonkurs/Montag/strings6
Executable file
13
Lehrer/pythonkurs/Montag/strings6
Executable file
@@ -0,0 +1,13 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Stringtheorie"
|
||||
|
||||
print(string)
|
||||
print(string.lower())
|
||||
print(string.upper())
|
||||
|
||||
print(string[0].lower()+string[1:])
|
||||
string = string[0].lower()+string[1:]
|
||||
|
||||
string = 'Übung'
|
||||
print(string[0].lower()+string[1:])
|
||||
16
Lehrer/pythonkurs/Montag/strings7
Executable file
16
Lehrer/pythonkurs/Montag/strings7
Executable file
@@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
string = "Stringtheorie"
|
||||
|
||||
# .count() existiert auch bei Listen
|
||||
print("Haeufigkeit von e:", string.count('e'))
|
||||
print("Haeufigkeit von a:", string.count('a'))
|
||||
|
||||
print("Index von e:", string.find('e'))
|
||||
# Achtung: liefert -1 bei Nicht-Finden, muss abgeprueft werden
|
||||
print("Index von a:", string.find('a'))
|
||||
|
||||
# .index() existiert auch bei Listen
|
||||
print("Index von e:", string.index('e'))
|
||||
# Achtung: Loest eine Exception aus, muss ggf. abgefangen werden
|
||||
print("Index von a:", string.index('a'))
|
||||
4
Lehrer/pythonkurs/Montag/testdict
Executable file
4
Lehrer/pythonkurs/Montag/testdict
Executable file
@@ -0,0 +1,4 @@
|
||||
#! /usr/bin/env python3
|
||||
testdict = {'hostname': 'notebook14', 'address': '192.168.1.214', 'maker': 'Lenovo', 'type': 'T530', 'ramsize': 16, 'ssd': True}
|
||||
|
||||
print(testdict['hostname'])
|
||||
23
Lehrer/pythonkurs/Montag/zahlen1
Executable file
23
Lehrer/pythonkurs/Montag/zahlen1
Executable file
@@ -0,0 +1,23 @@
|
||||
#! /usr/bin/env python3
|
||||
|
||||
integer = 13
|
||||
zahl1 = "12"
|
||||
|
||||
print(integer, zahl1)
|
||||
|
||||
# Explizite Typ-Umwandlung in Integer
|
||||
ergebnis = integer + int(zahl1)
|
||||
print(ergebnis)
|
||||
|
||||
# Achtung: Python3 erzeugt float als Ergebnis, Python2 ein Integer
|
||||
print(ergebnis, "/ 5 =", ergebnis / 5)
|
||||
# Explizite Integer-Division
|
||||
print(ergebnis, "/ 5 =", ergebnis // 5)
|
||||
|
||||
print(ergebnis, "/ 4 =", ergebnis // 4)
|
||||
# Modulo = ganzzahliger Rest der Division
|
||||
print(ergebnis, "% 4 =", ergebnis % 4)
|
||||
|
||||
# Power-Funktion, Exponent-Funktion
|
||||
print("2 hoch 10 =", 2 ** 10)
|
||||
print("10 hoch 3 =", 10 ** 3)
|
||||
Reference in New Issue
Block a user