Ana sayfa Genel Python – Döngüler ve For Döngüleri

Python – Döngüler ve For Döngüleri

2850
92
PAYLAŞ

Döngü Yapılarını Kullanma

Şimdiye kadar yazdığımız programlarda yazdığımız programlar bir defa çalışıyor ve sona eriyordu. Ancak biz çoğu zaman programlarımızın belli koşullarda çalışmasını sürekli devam ettirmesini ve işlemlerini tekrar etmesini isteriz. İşte bunları yapmamızı sağlayan yapılara döngü diyoruz.

Döngüler bütün programlama dillerinde bulunan ve belli koşullarda işlemlerini sürekli tekrar eden yapılardır. İsterseniz gerçek hayattaki programlara bakarak döngü mantığını anlamaya çalışalım.

Örneğin , siz ATM makinesine gidip kartınızı yerleştiriyorsunuz ve program başlıyor. Para Çekme, Para Yatırma , Vergileri Ödeme gibi işlemleri tekrar tekrar gerçekleştiriyorsunuz. Programın sona ermesi ise Kart İade seçeneği ile gerçekleşiyor. Yani siz Kart İade tuşuna basmadığınız sürece ATM makinesi çalışmaya devam ediyor. Buna bakarak ,aslında ATM makinesi döngü yapılarını kullanıyor diyebiliriz.

Başka bir örnek düşünelim. Örneğin siz bir siteye login olma işlemi gerçekleştiriyorsunuz. Biz kullanıcı adı ve parolayı yanlış girdiğimiz sürece program sürekli bize kullanıcı adı ve parola soruyor. Programın sona ermesi ise biz kullanıcı adı ve parolayı doğru girdiğimizde gerçekleşiyor. Yine burada da siz döngü yapılarının kullanıldığını düşünebilirsiniz.

For Döngüleri

Şimdi de Pythondaki for döngülerinin yapısını ve for döngülerinin kullanım alanlarını öğrenelim. Ancak ondan önce , Pythondaki in operatörünü öğrenmeye çalışalım.

in Operatörü

Pythondaki in operatörü , bir elemanın başka bir listede,demette veya stringte (karakter dizileri) bulunup bulunmadığını kontrol eder. Kullanımı şu şekildedir;

for Döngüsü

for Döngüsü , listelerin ,demetlerin, stringlerin ve hatta sözlüklerin üzerinde dolaşmamızı sağlayan bir döngü türüdür. Yapısı şu şekildedir.

Bu yapı bize şunu söyler;

for döngüsünü daha iyi anlamak için örneklerimize bakalım.

Listeler Üzerinde Gezinmek



Karakter Dizileri Üzerinde Gezinmek (Stringler)


Demetler üzerinde gezinmek (Demetler)

Demetlerin üzerinde for döngüsü uygularken aslında çok pratik bir yöntem bulunuyor. Aşağıdaki örneğe bakalım.



Sözlükler üzerinde gezinmek (Dictionary)

Hatırlarsanız, sözlükler konusunda 3 adet metod görmüştük. (keys(),values(),items()). İsterseniz bunları burada hatırlayalım.

Python sonuçları dict_keys,dict_values,dict_items olarak vermesine rağmen , bunlar üzerinde liste veya demet üzerinde gezinir gibi for döngüsüyle gezinebiliriz.

İşte for döngüsü bu kadar! Bir sonraki konuda while döngülerini anlamaya çalışacağız.

92 YORUMLAR

  1. Usually I do not read post on blogs, but I would like to say that this write-up very forced me to try and do so! Your writing style has been surprised me. Thanks, very nice post.

  2. Simply wish to say your article is as amazing. The clarity in your post is just spectacular and i could assume you’re an expert
    on this subject. Fine with your permission let me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please carry on the enjoyable work.

  3. hello!,I really like your writing so a lot! share we communicate more about your
    post on AOL? I require an expert on this house to resolve my problem.
    May be that is you! Having a look forward to see you.

  4. I keep listening to the news bulletin lecture about receiving free online grant applications so I have been looking around for the most excellent site to get one. Could you tell me please, where could i get some?

  5. Remarkable issues here. I’m very glad to look your article.
    Thank you a lot and I am having a look forward
    to contact you. Will you please drop me a e-mail?

  6. Excellent read, I just passed this onto a colleague who was doing a little research on that. And he actually bought me lunch since I found it for him smile Thus let me rephrase that: Thank you for lunch! “Bill Dickey is learning me his experience.” by Lawrence Peter Berra.

  7. Hello there! This post couldn’t be written any better! Reading this post reminds me of my previous room mate! He always kept talking about this. I will forward this write-up to him. Fairly certain he will have a good read. Many thanks for sharing!

  8. What i do not understood is in truth how you are now not actually a lot more smartly-liked than you might be now. You’re very intelligent. You realize thus considerably on the subject of this matter, produced me in my view believe it from so many various angles. Its like men and women don’t seem to be fascinated except it is one thing to do with Lady gaga! Your own stuffs nice. All the time handle it up!

  9. It is appropriate time to make some plans for the future and it is time to be happy. I’ve read this post and if I could I desire to suggest you some interesting things or tips. Maybe you can write next articles referring to this article. I desire to read even more things about it!

  10. Thanks for sharing excellent informations. Your web site is very cool. I am impressed by the details that you’ve on this website. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched all over the place and simply couldn’t come across. What a perfect web-site.

  11. I like the helpful information you provide to your articles.
    I’ll bookmark your blog and check once more here regularly.
    I’m rather certain I’ll be informed many new stuff right here!
    Good luck for the next!

  12. I got what you intend, regards for posting.Woh I am happy to find this website through google. “Food is the most primitive form of comfort.” by Sheila Graham.

  13. Thanks a bunch for sharing this with all of us you really know what you’re talking about! Bookmarked. Please also visit my site =). We could have a link exchange agreement between us!

  14. A lot of thanks for your entire hard work on this site. Gloria take interest in working on internet research and it’s really simple to grasp why. Many of us notice all regarding the compelling way you present reliable tips and hints on your web site and as well recommend participation from others on this subject so our favorite princess is always becoming educated so much. Take pleasure in the rest of the year. You’re the one conducting a brilliant job.

  15. Great ?V I should definitely pronounce, impressed with your website. I had no trouble navigating through all tabs as well as related info ended up being truly simple to do to access. I recently found what I hoped for before you know it at all. Reasonably unusual. Is likely to appreciate it for those who add forums or something, web site theme . a tones way for your client to communicate. Nice task..

  16. Thanx for the effort, keep up the good work Great work, I am going to start a small Blog Engine course work using your site I hope you enjoy blogging with the popular BlogEngine.net.Thethoughts you express are really awesome. Hope you will right some more posts.

  17. I would like to thnkx for the efforts you’ve put in writing this website. I’m hoping the same high-grade website post from you in the upcoming also. Actually your creative writing abilities has encouraged me to get my own website now. Really the blogging is spreading its wings quickly. Your write up is a great example of it.

  18. I am now not certain the place you are getting your info, but good topic. I must spend some time finding out more or figuring out more. Thanks for wonderful information I was on the lookout for this info for my mission.

  19. Magnificent goods from you, man. I’ve understand your stuff previous to and you’re just extremely fantastic. I actually like what you’ve acquired here, really like what you are stating and the way in which you say it. You make it enjoyable and you still take care of to keep it sensible. I cant wait to read much more from you. This is really a terrific web site.

  20. I think this is among the most vital information for me. And i’m glad reading your article. But want to remark on some general things, The web site style is perfect, the articles is really great : D. Good job, cheers

  21. Hello there, simply turned into alert to your weblog via Google, and located that it is truly informative. I’m going to be careful for brussels. I’ll be grateful should you proceed this in future. Numerous folks shall be benefited out of your writing. Cheers!

  22. Wow that was unusual. I just wrote an incredibly long comment but after I clicked submit my comment didn’t appear. Grrrr… well I’m not writing all that over again. Anyhow, just wanted to say superb blog!

  23. great post, very informative. I wonder why the other specialists of this sector do not notice this. You must continue your writing. I’m sure, you’ve a huge readers’ base already!

  24. Hey there just wanted to give you a quick heads up and let you know a few of the pictures aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same results.

  25. Hocam Merhaba,
    Listeler Üzerinde Gezinmek başlığı altında 2. slaytta çıktı olarak aşağıdaki şekilde alabiliyorum toplam 28 değil cevap.

    Ben mi bir hata yapıyorum acaba? Yardımcı olabilirseniz sevinirim. Çalıştırdığım kodu da belirttim

    liste =[1,2,3,4,5,6,7]
    toplam=0
    for eleman in liste:
    toplam += eleman
    print(“Toplam”,toplam)
    Çıktı
    (‘Toplam’, 1)
    (‘Toplam’, 3)
    (‘Toplam’, 6)
    (‘Toplam’, 10)
    (‘Toplam’, 15)
    (‘Toplam’, 21)
    (‘Toplam’, 28)

  26. Wonderful items from you, man. I’ve remember your stuff prior to and you are just extremely great. I really like what you’ve received here, certainly like what you’re saying and the best way by which you say it. You make it enjoyable and you still take care of to keep it wise. I cant wait to read far more from you. This is actually a great website.

  27. I liked up to you will obtain carried out right here. The sketch is attractive, your authored material stylish. nevertheless, you command get bought an nervousness over that you would like be handing over the following. in poor health certainly come more in the past once more as precisely the similar just about a lot steadily within case you protect this increase.

  28. 以低能量的1064-Q激光反覆掃於皮膚表面,逐步改善皮膚色素問題。 治療時產生的熱能能促進膠原蛋白的再生,回復肌膚彈性。 使用7mm平行光光頭,使輸出的激光更溫和及均勻。功效: 去除紋身 美白及去除面毛 令整體膚色更白更均勻 減淡及去除荷爾蒙斑或反黑 增加皮膚膠原蛋白,改善皮膚彈性 減淡深層色斑 : 黃褐斑,荷爾蒙斑,蝴蝶斑 以低能量的1064-QS激光反覆掃於皮膚表面,逐步改善皮膚色素問題 使用8-10mm平行光光頭,使輸出的激光 更溫和及均勻 1. 激光能透進皮膚深層 2. 激光被黑色素吸收 3. 產生熱能將黑色素體分解 4. 被呑噬細胞吸收及排出體外

  29. I would like to thnkx for the efforts you have put in writing this blog. I am hoping the same high-grade blog post from you in the upcoming as well. In fact your creative writing abilities has inspired me to get my own blog now. Really the blogging is spreading its wings quickly. Your write up is a good example of it.

  30. Thank you for sharing excellent informations. Your web site is very cool. I am impressed by the details that you¦ve on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found simply the information I already searched all over the place and simply could not come across. What an ideal web site.

  31. Heya i am for the primary time here. I came across this board and I find It really useful & it helped me out much. I hope to give one thing back and aid others such as you aided me.

  32. Hi there! Someone in my Facebook group shared this website with us so I
    came to check it out. I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers!
    Terrific blog and terrific design and style.

  33. Hi there just wanted to give you a quick heads up. The text
    in your post seem to be running off the screen in Chrome.
    I’m not sure if this is a format issue or something to do with web browser compatibility but I figured I’d post to let you know.
    The design look great though! Hope you get the problem solved soon. Cheers

  34. This blog is definitely rather handy since I’m at the moment creating an internet floral website – although I am only starting out therefore it’s really fairly small, nothing like this site. Can link to a few of the posts here as they are quite. Thanks much. Zoey Olsen

  35. When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!

  36. Along with the whole thing that seems to be developing inside this specific subject material, your perspectives happen to be rather radical. Having said that, I appologize, because I do not give credence to your whole idea, all be it exciting none the less. It appears to us that your remarks are generally not totally justified and in actuality you are generally your self not really thoroughly certain of your point. In any case I did appreciate reading it.

  37. Hey very nice web site!! Man .. Excellent .. Amazing .. I’ll bookmark your website and take the feeds additionally…I’m glad to seek out numerous helpful information right here within the submit, we need work out more strategies on this regard, thank you for sharing. . . . . .

  38. I’ve been absent for some time, but now I remember why I used to love this web site. Thank you, I?¦ll try and check back more often. How frequently you update your website?

  39. We’re a bunch of volunteers and starting a brand new scheme in our community. Your site offered us with valuable info to work on. You have performed an impressive task and our entire community can be grateful to you.

  40. I don’t even know how I ended up right here, but I assumed this publish was once good. I do not know who you are but definitely you’re going to a well-known blogger for those who aren’t already 😉 Cheers!

  41. I was just seeking this info for a while. After 6 hours of continuous Googleing, at last I got it in your website. I wonder what’s the lack of Google strategy that do not rank this type of informative web sites in top of the list. Normally the top web sites are full of garbage.

BİR CEVAP BIRAK

Lütfen yorumunuzu giriniz
Buraya isminizi giriniz