Ana sayfa Genel Python – Koşullu Durumlar – if,elif ve else

Python – Koşullu Durumlar – if,elif ve else


Koşullu Durumlar – if – elif – else koşullu durumları

Önceki konumuzda koşullu durumlardaki if-else kalıplarımızı öğrendik. Bu bölümde de if-elif-else kalıplarını öğrenmeye çalışacağız.


if-elif-else Blokları

Önceki konumuzda koşullu durumlarımızla sadece tek bir koşulu kontrol edebiliyorduk. Ancak programlamada bir durum bir çok koşula bağlı olabilir. Örneğin bir hesap makinesi programı yazdığımızda kullanıcının girdiği işlemlere göre koşullarımızı belirleyebiliriz. Bu tür durumlar için if-elif-else kalıplarını kullanırız. Kullanımı şu şekildedir;

Programlarımızda, Kaç tane koşulumuz var ise o kadar elif bloğu oluşturabiliriz. Ayrıca else in yazılması zorunlu değildir. if – elif – else kalıplarında, hangi koşul sağlanırsa program o bloğu çalıştırır ve if-elif-blokları sona erer. Şimdi isterseniz kullanıcıya işlem seçtirdiğimiz bir programla , bu kalıbı öğrenmeye başlayalım.

Programlarda else kalıbının kullanılmasına gerek yoktur.Buradaki kodda biz diğer durumlar için sadece opsiyonel bir else bloğu koyduk. Kodumuz else bloğu olmadan da çalışabilecektir. Ancak bu durumda yanlış bir işlem girilirse ekrana herhangi bir şeyin yazılmadığını göreceğiz. Yani, else bloğu kullanmak tamamen size bağlı.

Peki , if koşulu olmadan elif bloklarını yazmak mümkün mü ? Pythonda böyle bir kullanım hataya yol açacaktır.

if-if-if Blokları

Bu blokları öğrenmeden önce isterseniz öğrendiğimiz bilgilerle, bir harf notu hesaplama sistemi yapalım. Daha sonra bu kalıpları anlamaya çalışalım.

Burada eğer herhangi bir bloğumuz koşulu sağlarsa print işlemi gerçekleşecek ve programımız sonlanacaktır. Ancak acaba elif bloklarını if bloklarına çevirirsek programımız nasıl çalışacak ? Hemen bakalım.

Burada gördüğümüz gibi programımız beklenmedik bir şekilde çalıştı. Çünkü Pythonda programlar her zaman bütün if bloklarını kontrol eder ve koşullar doğruysa bu blokları çalıştırır. İşte böyle not hesaplama gibi programlarda elif kullanmamızın sebebi budur.


  1. Wow! This could be one particular of the most beneficial blogs We’ve ever arrive across on this subject. Actually Magnificent. I’m also an expert in this topic so I can understand your hard work.

  2. Can I just say what a relief to find someone who actually knows what theyre talking about on the internet. You definitely know how to bring an issue to light and make it important. More people need to read this and understand this side of the story. I cant believe youre not more popular because you definitely have the gift.

  3. I precisely desired to thank you very much once again. I do not know what I would’ve sorted out in the absence of the entire basics shown by you about such a area of interest. Completely was a real terrifying condition in my opinion, but seeing the very professional approach you resolved it took me to cry for gladness. I will be thankful for your help and thus sincerely hope you know what an amazing job you are doing teaching men and women through the use of your site. I am sure you’ve never met all of us.

  4. Wonderful goods from you, man. I’ve take into account your stuff prior to and you’re
    simply too excellent. I actually like what you have got right here, really like
    what you’re saying and the best way in which you assert it.
    You are making it entertaining and you still care for to keep it smart.
    I can’t wait to read much more from you. That is actually a tremendous
    web site.

  5. I just could not go away your web site before suggesting that I
    actually enjoyed the standard information a person provide in your
    visitors? Is going to be back incessantly in order to investigate cross-check new posts

  6. I do agree with all the ideas you have presented in your post. They’re really convincing and will certainly work. Still, the posts are too short for starters. Could you please extend them a bit from next time? Thanks for the post.

  7. Today, I went to the beach with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear
    and screamed. There was a hermit crab inside and it pinched
    her ear. She never wants to go back! LoL I know this is
    totally off topic but I had to tell someone!

  8. My coder is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the costs. But he’s tryiong none the less. I’ve been using Movable-type on various websites for about a year and am concerned about switching to another platform. I have heard good things about Is there a way I can import all my wordpress posts into it? Any help would be really appreciated!

  9. Everyone loves what you guys are up too. Such clever work and coverage! Keep up the amazing works guys I’ve included you guys to my own blogroll.

  10. Hi, I think your site might be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, fantastic blog!

  11. Hi, I think your site might be having browser compatibility issues. When I look at your website in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping. I just wanted to give you a quick heads up! Other then that, fantastic blog!

  12. I simply couldn’t leave your site prior to suggesting that I actually loved the standard info an individual supply to your guests? Is going to be again incessantly to inspect new posts

  13. Woah! I’m really loving the template/theme of this site. It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between user friendliness and visual appeal. I must say that you’ve done a awesome job with this. Additionally, the blog loads super quick for me on Safari. Excellent Blog!

  14. Do you have a spam problem on this site; I also am a blogger, and I was wanting to know your situation; many of us have created some nice methods and we are looking to trade methods with others, why not shoot me an e-mail if interested.

  15. I like what you guys are up also. Such clever work and reporting! Carry on the superb works guys I¦ve incorporated you guys to my blogroll. I think it will improve the value of my web site 🙂

  16. I think other web-site proprietors should take this website as an model, very clean and fantastic user friendly style and design, let alone the content. You are an expert in this topic!

  17. Very interesting topic, thanks for putting up. “Nothing is more wretched than the mind of a man conscious of guilt.” by Titus Maccius Plautus.

  18. Hiya, I am really glad I’ve found this info. Today bloggers publish just about gossips and net and this is actually annoying. A good website with interesting content, that is what I need. Thanks for keeping this site, I’ll be visiting it. Do you do newsletters? Can’t find it.

  19. Have you ever thought about adding a little bit more than just your articles? I mean, what you say is fundamental and everything. However imagine if you added some great photos or video clips to give your posts more, “pop”! Your content is excellent but with images and videos, this site could certainly be one of the very best in its niche. Great blog!

  20. Hello there,

    My name is Aly and I would like to know if you would have any interest to have your website here at promoted as a resource on our blog ?

    We are in the midst of updating our broken link resources to include current and up to date resources for our readers. Our resource links are manually approved allowing us to mark a link as a do-follow link as well
    If you may be interested please in being included as a resource on our blog, please let me know.


  21. 我們採用國際及美國食品及藥物管理局FDA認可的CO2 激光儀 LUTRONICS® SPECTRA SPR, 具安全性, 準確度高 . 二氧化碳激光可安全地去除皮膚上的癦痣、肉粒、疣、老人斑等問題。此激光的幼細光束可準確及直接地將要去除的組織氧化,過程快捷,傷口細小及乾淨,對周圍的皮膚傷害減至最少。一般1-2次就可永久去除。

  22. I’m really enjoying the design and layout of your website. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme? Outstanding work!

  23. Many thanks a lot to get spreading that operating folks you undoubtedly realize what you’re really dealing with! Book-marked.. video vlogger terbaik Please in addition seek advice from my site Means). We may possess a weblink industry agreement in between people

  24. Many thanks a lot to get spreading that operating folks you undoubtedly realize what you’re really dealing with! Book-marked.. video vlogger terbaik Please in addition seek advice from my site Means). We may possess a weblink industry agreement in between people

  25. What¦s Going down i am new to this, I stumbled upon this I’ve found It absolutely helpful and it has aided me out loads. I’m hoping to give a contribution & aid other users like its helped me. Good job.

  26. Undeniably believe that which you stated. Your favorite reason seemed to be on the web the easiest thing to be aware of. I say to you, I certainly get annoyed while people think about worries that they plainly don’t know about. You managed to hit the nail upon the top and also defined out the whole thing without having side-effects , people can take a signal. Will likely be back to get more. Thanks

  27. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I get in fact enjoyed account your blog posts. Anyway I will be subscribing to your augment and even I achievement you access consistently fast.

  28. Having read this I thought it was very informative. I appreciate you taking the time and effort to put this article together. I once again find myself spending way to much time both reading and commenting. But so what, it was still worth it!

  29. There are some interesting points in time on this article however I don’t know if I see all of them center to heart. There’s some validity however I will take hold opinion till I look into it further. Good article , thanks and we would like extra! Added to FeedBurner as effectively

  30. I discovered your blog site on google and check a few of your early posts. Continue to keep up the very good operate. I just additional up your RSS feed to my MSN News Reader. Seeking forward to reading more from you later on!…

  31. You can definitely see your enthusiasm in the work you write. The sector hopes for more passionate writers like you who are not afraid to say how they believe. At all times go after your heart.


Lütfen yorumunuzu giriniz
Buraya isminizi giriniz