<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hasan Şekerci on Medium]]></title>
        <description><![CDATA[Stories by Hasan Şekerci on Medium]]></description>
        <link>https://medium.com/@HasanSekerci?source=rss-97dbae34e141------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*qTsLKvYiUjNj8jwm</url>
            <title>Stories by Hasan Şekerci on Medium</title>
            <link>https://medium.com/@HasanSekerci?source=rss-97dbae34e141------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 17:24:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@HasanSekerci/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The Art of Pythonic Code]]></title>
            <link>https://medium.com/@HasanSekerci/the-art-of-pythonic-code-be6a952e6fa5?source=rss-97dbae34e141------2</link>
            <guid isPermaLink="false">https://medium.com/p/be6a952e6fa5</guid>
            <category><![CDATA[pythonic]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[seniors]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Hasan Şekerci]]></dc:creator>
            <pubDate>Sun, 07 Dec 2025 23:02:48 GMT</pubDate>
            <atom:updated>2025-12-11T13:06:18.017Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o4yJJ2Av0vjScHhd" /></figure><p>Coding is not just about giving commands to a computer. It is about communicating with the person who will read your code later. Python gives you tools to turn your code into a piece of art. But ask yourself: Does your code just “work” or is it “Pythonic” ?</p><p>Let’s look at how to write code that is readable and safe. We will also cover tips that will impress employers when they review your work.</p><h4>1-Combining Two Lists “zip()” :</h4><p>The name of the zip function in Python is no coincidence. It actually comes from the word <strong>&#39;Zipper&#39;</strong>.</p><p>Think of your jacket. It has teeth on the right side and teeth on the left side. When you pull the zipper up, the teeth from these two separate sides come together and interlock, one by one.</p><p>Let’s say you have a map application. You have <strong>Latitude (X)</strong> values in one list and <strong>Longitude (Y)</strong> values in the other</p><p><strong>The Classical Way</strong> :</p><p>This is like putting two lists side by side and tracking them with your finger, saying, ‘The first one here, the first one there…’ This method is very error-prone.</p><pre>xCoordinates = [10, 20, 30]<br>yCoordinates = [5, 15, 25]<br><br>for coordinate in range(len(xCoordinates)):<br>    print(f&quot;Point: {xCoordinates[coordinate]}, {yCoordinates[coordinate]}&quot;)</pre><p><strong>The Pythonic Way</strong> :</p><p>The “zip()” command starts from the beginning of both lists. It takes the elements in order and combines them into a package (<strong>tuple</strong>). It stops automatically as soon as one of the lists runs out. Thus saving us from dealing with indexes.</p><pre>xCoordinates = [10, 20, 30]<br>yCoordinates = [5, 15, 25]<br>for x, y in zip(xCoordinates, yCoordinates):<br>    print(f&quot;Point: {x}, {y}&quot;)  </pre><p>If you want to turn this pairing into permanent data, you don’t need to write a loop. You can very practically convert it directly into a “dictionary”.</p><pre>xCoordinates = [10, 20, 30]<br>yCoordinates = [5, 15, 25]<br>coordinateDict = dict(zip(xCoordinates, yCoordinates))</pre><h4>2- If commands at Single Line :</h4><p>Let’s say we want to mark a student as “Passed” or “Failed” based on their grade.</p><p><strong>The Classical Way </strong>:</p><pre>score = 85<br>state = &quot;&quot;<br><br>if score &gt;= 60: <br>   state = &quot;Passed&quot;<br>else : <br>   state = &quot;Failed&quot;<br><br>print(state)<br></pre><p><strong>The Pythonic Way</strong> :</p><pre>score = 85<br>state = &quot;Passed&quot; if score &gt;= 60 else &quot;Failed&quot;<br><br>print(state)<br></pre><p>In this structure, the value written before the if is assigned to the variable if the condition is true. The value after else is used if the condition is false.</p><p>The main reason we write code this way is clarity. We can understand the code’s goal (assigning a variable) at a single glance. Our eyes do not need to jump between the lines, and the code becomes shorter.</p><p>However, we “must remember that shorter”<em>is not “</em>always better”. If the if block is complex, we should not use this method. We prefer this one-line approach only when the condition is simple, usually for variable assignments.</p><h4>3- List Comprehensions :</h4><p>Imagine we have a list of numbers. We want to find the even numbers and create a new list with their squares.</p><p><strong>The Classical Way </strong>:</p><pre>numbers = [1,2,3,4,5,6,7,8,9,10]<br>squares = []  #list of Squares<br><br>for number in numbers :<br>    if number % 2 == 0: #It checks the remainder of the number divided by 2, that is, even numbers.  <br>       squares.append(number ** 2)      <br>print(squares)<br># Output : [4, 16, 36, 64, 100]<br></pre><p><strong>The Pythonic Way</strong> :</p><pre>numbers = [1,2,3,4,5,6,7,8,9,10]<br><br>squares = [number ** 2 for number in numbers if number %2 == 0]<br># here , number ** 2  same that  squares.append(number ** 2)<br><br>print (squares)<br># Output : [4, 16, 36, 64, 100]</pre><p>Remember how we wrote for and if blocks in a single line? The only difference here is that we define the list and add the result (number ** 2) at the same time. This makes our code both shorter and more Pythonic.</p><p>Now, let’s move on to the part where we start thinking a bit more like a “Senior Developer ”.</p><h4>4- Try-Except :</h4><p>Using “try-except” in software is like placing a safety net under acrobats in a circus.</p><p>The acrobat (your code) might fall (encounter an error).</p><p><strong>If there is a net:</strong> They fall, get back up, and the show goes on.</p><p><strong>If there is no net:</strong> The show ends disastrously (the program crashes)</p><p>Imagine you have a grocery list. It contains only 3 fruits: Apple, Pear, and Banana. What happens if you go to the counter and ask, <strong>‘</strong>Give me the 4th fruit<strong>’</strong>?</p><p><strong>Without try-except</strong>:</p><pre>fruits = [&quot;Apple&quot;, &quot;Pear&quot;, &quot;Banana&quot;]<br><br>print(fruits[3]) <br><br># Output: IndexError </pre><p>It yells, ‘There are not that many items in the list!’ and crashes the program.</p><p><strong>With try-except</strong>:</p><pre>fruits = [&quot;Apple&quot;, &quot;Pear&quot;, &quot;Banana&quot;]<br>try : <br>  print(fruits[3])<br>except IndexError:<br>  print(&quot;Error: There isn&#39;t that much fruit in the list&quot;)<br># output: The program does not crash. It simply prints: &#39;There are not that many fruits in the basket!&#39; </pre><p>Python tries to find the item. If it cannot find it, instead of giving an error, it reads the message we prepared “except”.</p><p>I learned this the hard way. In one of my past projects (back when AI was not this advanced), I spent days trying to find a single error. It was a very painful and exhausting process. After that day, I started using try-except blocks everywhere.</p><h4>5- Script Security :</h4><p>Every file you write in Python is actually a potential <strong>module</strong>. This means you can “import” and use a calculator script you wrote in another project. However, there is a common mistake developers make. After defining their functions, they often write “print()” statements or test code at the bottom of the file.</p><p>When you import this file into another project, that test code runs immediately and unintentionally. In software, this is a dangerous situation we call an <strong>‘</strong>unwanted side effect<strong>’</strong>.</p><p>A Senior Developer uses these lines to control whether the script should run immediately or just sit there as a library.</p><p>Imagine you coded a robot. Its only job is to say <strong>‘</strong>Hello<strong>’</strong>.</p><p><strong>Classical Way :</strong></p><p>Whenever you see this robot (even if you call it into another file), it tries to greet you.</p><pre>def greeting():<br>    return &quot; Hello !&quot;<br><br>print(greeting())<br>#Because of this line, everyone who imports the file will see this text</pre><p><strong>Way of Senior :</strong></p><p>This robot speaks only if you run it specifically to test it (by pressing the Run button). When called into another project (imported), it waits silently for your orders.</p><pre>def greeting():<br>    return &quot; Hello !&quot;<br><br>if __name__ == &quot;__main__&quot;:<br>    print(&quot;Tester Mode &quot;)<br>    print(greeting())</pre><p>In other words, these lines are the ‘Backstage<strong>’</strong> of your code.The<strong> audience</strong> (other files) cannot see this part. It runs only when the director (you) runs the file directly.</p><h4>6- Type Hinting:</h4><p>When writing a function, it is important to know what kind of data it expects (a number? text?) and what it will give back. Most developers rely on Python’s flexibility and do not write the types. The person reading the code (or <strong>you</strong>, 6 months later) is forced to guess: “Does this function want a number or a list?”</p><p>A Senior Developer uses <strong>Type Hinting</strong> to hang signs on the input and output doors of the code.</p><p><strong>Classical Way :</strong></p><pre>def card(name,age):<br>    return &quot;Dear &quot; + name+ &quot;, Age: &quot; + str(age)</pre><p><strong>Pythonic Way :</strong></p><pre>def card(name: str, age: int) -&gt; str: #here,shows that output type of function<br>    return f&quot;Dear {name}, Age: {age}&quot;</pre><p>Here, everything is clear. The arrow (-&gt; str) tells us;When this process is finished, I will give you a text (string).</p><p>Writing code in Python is easy, but writing Pythonic code is an art.The 6<strong> </strong>touches we explored today make your code understandable not just for computers, but for humans too.</p><p>Remember, a good programmer is not the one who writes complex code. A good programmer is the one who can explain complex tasks simply.</p><p>Hasan Şekerci</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be6a952e6fa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python’da For ve While Döngüleri]]></title>
            <link>https://medium.com/@HasanSekerci/pythonda-for-ve-while-d%C3%B6ng%C3%BCleri-1fb978925b34?source=rss-97dbae34e141------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fb978925b34</guid>
            <category><![CDATA[cpython]]></category>
            <category><![CDATA[while]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-loop]]></category>
            <category><![CDATA[for]]></category>
            <dc:creator><![CDATA[Hasan Şekerci]]></dc:creator>
            <pubDate>Sun, 31 Aug 2025 13:49:44 GMT</pubDate>
            <atom:updated>2025-09-01T11:16:44.773Z</atom:updated>
            <content:encoded><![CDATA[<h3>Pythonda For Ve While Döngüleri</h3><p>Yazılım öğrenirken en sık karşımıza çıkan yapılar döngülerdir ve yazılımın olmazsa olmazları arasındadır. Döngüleri günlük hayata benzetecek olursak bir şeyi tekrar tekrar yapmaktır mesela 80 sayfalık bir kitap hayal edin. Kitabı bitirmek için okurken tekrar tekrar sayfa çevireceksiniz.80 kere sayfa çevirme işlemini yapacaksınız ya da en basit örneklerden kahvaltıyı düşünün her sabah kahvaltı yapmak ya da her gün işe gitmek gibi. Yazılımda da bazı işlerin tekrar tekrar yapılması gerekebiliyor, bunun için Pythonda tekrar etmenin 2 yolu vardır: <strong>for</strong> ve <strong>while</strong> döngüleri.</p><p>Şimdi hem yaşantımızdan örnekler kullanarak hem de basit kod örnekleriyle döngüler hakkında soru işareti bırakmayalım.</p><h3>For Döngüsü</h3><p><strong>For döngüsü</strong>, elimizde belli bir koleksiyon (list, tuple, dictionary)sayı aralığı ya da yineleyici (iterable) olduğunda tercih edilir. Yani aslında “kaç defa tekrar edeceğimiz” belliyse <strong>for döngüsü</strong> kullanırız.<strong>For döngüsü</strong> aslında <strong>while’</strong>a göre daha akıllıdır gibi düşünebiliriz çünkü bizim verdiğimiz görevi alır ve ne zaman döngüyü bitirmesi gerektiğine karar verebilir.</p><p>Düşünün ki posta kutunuza 5 tane mektup geldi. Her mektubu sırayla açmanız gerekiyor. Bu durumda kaç kez tekrar edeceğiniz belli: 5 kez. İşte bu tip senaryolar <strong>For </strong>döngüsünün alanıdır. Şimdi küçük bir kod örneğiyle durumu izah edeyim.</p><p>Kod bölmesi :</p><pre>mektuplar = [ &quot;A&quot; , &quot;B&quot; , &quot;C&quot; , &quot;D&quot; , &quot;E&quot; ] <br><br>for mektuplar in mektuplar: <br>    print ( &quot;Mektup olabilir:&quot; , mektup)</pre><p>Çıktı :</p><pre>Mektup oluşur: Bir <br>Mektup oluşur: B <br>Mektup açılır: C <br>Mektup oluşur: D <br>Mektup oluşur: E</pre><p>Çıktıda da görüldüğü üzere for döngümüz mektuplar listesine giriyor ve o listedeki her bir öğeyi(A,B,C,D,E) tek tek mektup değişkenine atıyor. Print ile mektup değişkenini ekrana bastırdığımızda ise her seferinde hangi mektupta olduğunu görebiliyoruz. Listedeki öğeler bitince de kendisi otomatik olarak döngüyü sonlandırıyor.</p><p>Peki for döngüsü koleksiyon(liste,demet,sözlük) olmadan oluşturalamaz mı ? Evet oluşturulabilir.Range Methodu ile belli bir aralık belirleyip o aralıkta dönmesini isteyebiliriz. (C programlama bilenler için burayı anlamak daha kolay olacaktır C’deki for döngüsüyle benzer çalışıyor)</p><p>Kod bölmesi :</p><pre>i ( 2 , 5 , 1 ) aralığındaysa : ( i  ) yazdır<br>   </pre><p>Çıktı :</p><pre>2 <br>3 <br>4</pre><p>Çıktıda görüldüğü gibi döngümüz önce range() methodu içerisine giriyor , ardından range methodunun ilki start ikincisi ise stop kısmı olarak çalışıyor.Yani 2(start)den başlayarak 5(stop)e kadar ekrana bastırıyor. 3. ise kaçar kaçar artacağını temsil ediyor. Yani 1er 1er artıyor. Pythonda stop dahil alınmadığı için 5i dahil almıyor ve 5e kadar dönüyor.</p><p>Dileyenler bu kısmı atlayıp direkt while döngüsüne geçebilir şimdi C programlama bilenler için aynı kod örneğini C ile açıklayacağım.</p><h3>C — Python For Döngüsü</h3><p>C programlamada for döngüsü oluştururken bir koleksiyon kullanılmaz. Tıpkı az önce öğrendiğimiz range() methodu gibi parantez içerisnde nasıl olması gerektiği belirtilir.</p><p>Kod bölmesi :</p><pre># include  &lt;stdio.h&gt;  // stdio.h kütüphanesi printf fonksiyonunun çalışması için eklenir. <br><br>int  main ()  { <br>    int i; <br>    for (i = 2 ; i &lt; 5 ; i += 1 ) { <br>        printf ( &quot;%d\n&quot; , i); <br>    } 0&#39;ı <br>    döndür  ; }<br><br></pre><p>Çıktı :</p><pre>2 <br>3 <br>4</pre><p>Burada da görüldüğü gibi i değişkenini tanımladıktan sonra for döngüsü içerisinde nereden başlayıp nerede birmesi gerektiğini sırasıyla yazıyoruz ve en sonunda da nasıl ilerlemesi gerektiğini söylüyoruz aslında range() methodu da C dilindeki for döngüsüne benzer bir döngü oluşturmamızı sağlar.</p><h3>While Döngüsü</h3><p><strong>While döngüsü</strong>, tekrar sayısı belirsiz olan durumlarda kullanılır. Yani döngü, bir koşul doğru olduğu sürece devam eder. Bir kahve makinesini hayal edin. Su bitene kadar çalışır. Kaç defa kahve yapacağını bilmiyorsunuz; sadece su bitene kadar devam edeceğini biliyorsunuz. İşte bu tam bir <strong>while döngüsü</strong> örneğidir. Tekrar sayısı belirsiz ancak koşul suyun bitmesi yani su bitince duracak.</p><p>Kod bölmesi :</p><pre>su = 5 <br><br>while su &gt; 0: <br>    print ( &quot;Bir kahve hazırlandı!&quot; ) <br>    su -= 1</pre><p>Çıktı :</p><pre>Bir kahve hazırlanacak! <br>Bir kahve hazırlanacak! <br>Bir kahve hazırlanacak! <br>Bir kahve hazırlanacak! <br>Bir kahve hazırlanacak!</pre><p>İşte burada da önce su değişkenine bir değer atadık(5) ve <strong>while </strong>döngüsüne su 0&#39;dan büyük olduğu sürece çalış dedik. Döngünün içerisinde de her döngü sonunda suyu bir azalttık. Böylece ilkinde geldi su 5 yabi 0&#39;dan büyük <strong>while True </strong>oldu ve döngü çalışmaya başladı ve ekrana bastırdı ardından suyu bir azalttık su 4&#39;e düştü. tekrar<strong> while</strong> kontrol etti su 0&#39;dan büyük mü? Evet, yani yine<strong> True</strong> döndü ve döngü bu şekilde su değişkeni 0 olana kadar devam etti ve su değişkeni 0 olduğunda <strong>while False</strong> oldu ve döngüden çıkıldı.</p><h3>For — While nerede hangisi tercih edilmeli ?</h3><p>For ve While’ı öğrendik ama nerede hangisini kullanmalıyız kısmında kafamızdaki soru işaretlerini iyice kaldıralım.</p><p><strong>for</strong> : Sabit bir kalıp varsa ve güncellemelere ihtiyaç duyulmuyor ise tercih edilebilir.</p><p><strong>while :</strong> Canlı bir akış var ve yeni güncellemeler ekleniyorsa tercih edilebilir.</p><p>Örneğin LinkedIn sayfasını oluşturacaksınız. Bir sayı belirleyip kullanıcı o sayıya basınca sayfaya girilecek <strong>.</strong> LinkedIn hesabındayken sürekli yenilenir ve canlı bir akış olur yani güncellemeler olur. Çıkınca güncelleme kapanır. Kullanıcı yokken sayfanın güncelleme yapmasına ve yeni kaynaklara gerek duyulmaz çünkü zaten kullanıcı bakmıyor. <strong>While</strong> böyleyken <strong>for </strong>ile<strong> </strong>kursaydık aynı döngüyü mesela 1000 kez yenile diye sabitleseydik, kullanıcı orada yokken bile yenilemeye devam ederdi ve gereksiz işlem yapılırdı.</p><p>Yani özetle;</p><p><strong>For</strong>: Tekrar sayıları sabitse, belirli bir liste/kalıp üzerinde işlem yapılıyorsa kullanılır.</p><p><strong>While</strong> : Tekrar sayısı belirsizse, koşul devam ettiği sürece çalışması gerekiyorsa kullanılır.</p><p>Gördüğünüz gibi ister posta kutunuzu açıyor olun, ister kahve makinenizi çalıştırıyor olun, döngüler hayatın her yerinde.</p><p><strong>Hasan Şekerci</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fb978925b34" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>