Slide 1

Slide 1 text

Python pratikleri

Slide 2

Slide 2 text

The zen of Python Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

Slide 3

Slide 3 text

a = 21 
 b = 42 
 Soru: a ile b değişkenlerinin değerlerini değiş-tokuş etmek istiyoruz. Nasıl? (a=42, b=21 olmalı.) swapping

Slide 4

Slide 4 text

Çözüm: a, b = b, a

Slide 5

Slide 5 text

a = 21 
 b = 42 
 Soru: a ile b değişkenlerinin değerlerini değiş-tokuş etmek istiyoruz. Nasıl? (a=42, b=21 olmalı.) swapping

Slide 6

Slide 6 text

teams = [“galatasaray”, “besiktas”, “fenerbahce”] Listenin eleman sırasına göre ekrana şu şekilde bir çıktıyı nasıl alırız? 
 1. galatasaray 2. besiktas 3. fenerbahce indexes

Slide 7

Slide 7 text

teams = [“galatasaray”, “besiktas”, “fenerbahce”] Listenin eleman sırasına göre ekrana şu şekilde bir çıktıyı nasıl alırız? 
 1. galatasaray 2. besiktas 3. fenerbahce indexes

Slide 8

Slide 8 text

scores = [21, 42, 88, 90, 100, 55]
 
 Bunların ortalamasını nasıl alırız? stdlib

Slide 9

Slide 9 text

scores = [21, 42, 88] students = [“John”, “Cemil”, “Altay”]
 Listelerin sırasına göre aşağıdaki gibi bir çıktıyı nasıl alırız? stdlib

Slide 10

Slide 10 text

for score, student in zip(students, scores): print "%s -> %s" % (score, student) stdlib

Slide 11

Slide 11 text

http://www.strawpoll.me/14460204 list gotchas

Slide 12

Slide 12 text

Açıklama: http://docs.python-guide.org/en/latest/ writing/gotchas/#mutable-default-arguments list gotchas

Slide 13

Slide 13 text

http://www.strawpoll.me/14460610 copy

Slide 14

Slide 14 text

scores = [17, 20] yeni bir liste oluşturalım. adı new_scores olsun. her score 3 ile çarpılsın. her eleman için çıkan sonuç tek sayı ise, +1 eklensin.
 
 beklenen değerler: new_scores = [52, 60] playing with lists

Slide 15

Slide 15 text

çözüm 1 (java programcısı) playing with lists

Slide 16

Slide 16 text

alternatif çözüm playing with lists

Slide 17

Slide 17 text

cluster_one = [1, 5, 10] cluster_two = [2, 10, 3] yeni bir liste oluşturalım. içinde ortak elemanlar olsun.
 
 beklenen değerler: cluster_three = [10] playing with lists

Slide 18

Slide 18 text

çözüm 1 playing with lists

Slide 19

Slide 19 text

çözüm2 playing with lists