Download - Pyladies 3.0 #5 funkcje i stingi
![Page 1: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/1.jpg)
PyLadies 3.0
#5: Więcej funkcji I stringów !
![Page 2: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/2.jpg)
Agenda
1. Tuple czyli krotka
2. Funkcje kwargs
3. Funkcje i ich magiczne gwiazdki
4. Formatowanie stringów
5. Funkcje stringów cd.
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 3: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/3.jpg)
Tuple czyli krotka
Tuple (po polsku krotka)
To niemutowalna lista tzn. że po jej
stworzeniu nie możemy jej edytować
przykłady krotek:
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 4: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/4.jpg)
Funkcja
to wydzielona część programu wykonująca
wcześniej zdefiniowane operacje.
Podprogramy stosuje się, aby uprościć
program główny i zwiększyć czytelność
kodu.
Funkcje wbudowane w Pythona to np.: len(),
abs()® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 5: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/5.jpg)
Funkcja – konstrukcja, wywołanie
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 6: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/6.jpg)
Funkcja z argumentem
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 7: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/7.jpg)
Funkcja z argumentem - kwargs
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 8: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/8.jpg)
Funkcja - zadania
1. Napisz funkcję, która policzy objętość
prostopadłościanu z podanych długości
boków podstawy i wysokości.
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 9: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/9.jpg)
Funkcja - zadania
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 10: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/10.jpg)
Funkcja - zadania
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 11: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/11.jpg)
Funkcja - zadania
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 12: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/12.jpg)
Funkcja *args
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 13: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/13.jpg)
Funkcja *args - zadanie
® 2016 Piotr Dyba PyLadies Poland 3.0
• Wykorzystujac funkcje i *args zaimplementuj funkche
range samemu
range([poczate], koniec, [skok]) która zwróci listę w
podanym zakresie.
W nawiasach kwadratowych zostaly ujete arguemnty nie
obiwązkowe.
Przykład użyca:
![Page 14: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/14.jpg)
Funkcja
*args - odp
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 15: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/15.jpg)
Funkcja zwracajaca wiele
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 16: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/16.jpg)
String: tuple i **
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 17: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/17.jpg)
String - zadanie
® 2016 Piotr Dyba PyLadies Poland 3.0
• Wykorzystujac formtowanie stringow napisz zaproszenie
urodzinowe, które będzie generowane na podstawie
danych:
imie, nazwisko, tytuł, przymitonik, ulubiony smak.
Przykład (czerwonym automatyczne wypelenie):
Prof. Andrzej Ruda,
Najblizszy przyjacielu chciałbym Cie zaprosic na swoje
urodziny na których będę serwowal Twój ulubion kokosowy
tort.
Piotr
![Page 18: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/18.jpg)
String
® 2016 Piotr Dyba PyLadies Poland 3.0
• capitalize
• casefold
• center
• count
• encode
• endswith
• expandtabs
• find
• format
• format_map
• index
• isalnum
• isalpha
• isdecimal
• isdigit
• isidentifier
• islower
• isnumeric
• isprintable
• isspace
• istitle
• isupper
• join
• ljust
• lower
• lstrip
• maketrans
• partition
• replace
• rfind
• rindex
• rjust
• rpartition
• rsplit
• rstrip
• split
• splitlines
• startswith
• strip
• swapcase
• title
• translate
• upper
• zfill
![Page 19: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/19.jpg)
String - join
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 20: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/20.jpg)
String - zadanie
® 2016 Piotr Dyba PyLadies Poland 3.0
1. Odszyfruj wiadomośc ze strony:
http://dyba.it/encodedm
sg
Wiedząc że litery zgubiły się w odmęcie innych znaków.
![Page 21: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/21.jpg)
String – zadanie: odp
® 2016 Piotr Dyba PyLadies Poland 3.0
http://dyba.it/encodedm
sg
![Page 22: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/22.jpg)
Q&A
® 2016 Piotr Dyba PyLadies Poland 3.0
![Page 23: Pyladies 3.0 #5 funkcje i stingi](https://reader031.vdocuments.pub/reader031/viewer/2022030402/587d91df1a28abcd648b7c8b/html5/thumbnails/23.jpg)
Zadanie domoweW interpreterze pythona wpisz: ‘import this’
Skopiuj tekst i przypisz go do zmiennej.
Nastepnie wypisz:
a)Wszystkie zdania które mają słowko is w
sobie.
b)Wszystkie zdania złożone (z ,)
c)Zmień wszystkie słowa rozpoczynajace się
z wielkiej litery na słowo Python
d)Dowiedz się czemu Holendrzy mogą nie
stosować zasady o tym że jest tylko jedna
słuszna droga aby rozwiązać dany
problem ;)® 2016 Piotr Dyba PyLadies Poland 3.0