This commit is contained in:
2022-11-21 17:23:21 +01:00
parent db7de0a6e8
commit 8657075f55
5 changed files with 110 additions and 2 deletions

View File

@@ -1,17 +1,36 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
#Liste
def myfor (t):
for l in t:
print(l)
numbers = [1, 2, 3, 5, 8, 10 ]
wortliste = ["Das", "ist", "das", "Haus", "vom", "Nikolaus"]
print(numbers)
print("Länge = ", len(numbers))
print("1 Element: ", numbers[0])
print("letztes Element: ", numbers[-1])
for i in numbers:
print(i)
myfor(numbers)
numbers[-1] = 55 #Elebend an der letzten Stelle ändern
copy = numbers[:] # Macht eine echte Kopie
print("letztes Element: ", numbers[-1])
numbers.append(21) #fügt ein Element hinzu
numbers.insert(0, 0) # fügt etwas an eine Stelle ein bei stelle 0 eine 0
print(numbers)
number_slice = numbers[0:3] #slice gibt nur den Index 0-3 an
number_slice1 = numbers[-4:-1]
myfor(number_slice)
print("what...")
myfor(number_slice1)
print("what...2")
print(copy)
myfor(wortliste)
string = "Ich bin ein Satz"
wortliste_string= string.split(' ')
myfor(wortliste_string)

View File

@@ -0,0 +1,10 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
string = "Ich bin ein Satz"
print(string)
wortliste_string= string.split(' ')
wortliste_string[2] = "kein"
string = ' '.join(wortliste_string)
print(string)
print ("check String :", "Satz" in string)

21
Montag/Stringtheorie.py Normal file
View File

@@ -0,0 +1,21 @@
#! /usr/bin/env python3
string = "Stringtheorie"
asciiwert = []
for what in string:
asciiwert.append(ord(what))
# ist das selbe wie [chr(what) for what in string ]
#Liste von Zeichen
char_list = [chr(value) for value in asciiwert ]
print(char_list)
string = ''.join(char_list)
print(string)
print(string.lower())
print(string.upper())
print(string[1].lower() + string[1:].upper())
print(string.count('e'))
print(string.count('a'))
print(string.index('e'))

41
Montag/dict.py Normal file
View File

@@ -0,0 +1,41 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
mydict = {}
mydict['hostname'] = "notebook43", "notebook2"
mydict['address'] = '192.168.1.243'
mydict['OS'] = 'Debian 5.10.149-2'
mydict['ssd'] = True
mydict['ramsize'] = 16
#####mydict['hostname'].append("notebook3")
print(mydict)
for key in mydict.keys():
print(key, '=', mydict[key])
print("-"*50)
for value in mydict.values():
print(value)
print("-"*50)
#Better
for key, value in mydict.items():
print(key, '=', value )
print("-"*50)
print(mydict.get('OS', "default_value"))
print("-"*50)
for test in mydict.get('hostname'):
print(test)
print("-"*50)
pop_value = mydict.pop("hostname")
print(pop_value)
print("-"*50)
key, value = mydict.popitem()
print(mydict)

17
Montag/schachbrett.py Normal file
View File

@@ -0,0 +1,17 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
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 z in zeilen:
for zelle in z:
print(zelle, end=' ')
else:
print()