{"id":32,"date":"2023-08-14T15:22:33","date_gmt":"2023-08-14T12:22:33","guid":{"rendered":"https:\/\/www.facadium.com.tr\/blog\/?p=32"},"modified":"2023-08-31T17:25:59","modified_gmt":"2023-08-31T14:25:59","slug":"python-if-elif-else-konusu","status":"publish","type":"post","link":"https:\/\/www.facadium.com.tr\/blog\/python-if-elif-else-konusu\/","title":{"rendered":"Python if-elif-else Konusu"},"content":{"rendered":"\n<p>Python yaz\u0131l\u0131m diline yeni ba\u015fl\u0131yorsan\u0131z \u00f6\u011frenmeniz gereken en \u00f6nemli konulardan birisi de if-elif-else konusudur. Di\u011fer yaz\u0131l\u0131m dillerinde de bu konu olduk\u00e7a \u00f6nemlidir. Bu ifadeler program\u0131m\u0131zda belirli i\u015flemleri yapmam\u0131zda kulland\u0131\u011f\u0131m\u0131z ko\u015ful ifadeleridir. \u015eimdi gelelim bu \u015fimdi \u00f6rnekler ile konuyu a\u00e7\u0131klamaya.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"if-i\u0307fadesi\">if \u0130fadesi<\/h3>\n\n\n\n<p>\u201cif\u201d ifadesi, e\u011fer anlam\u0131na gelir ve bir durumun do\u011fru mu yoksa yanl\u0131\u015f m\u0131 oldu\u011funu kontrol eder. ifadenin en basit hali \u015fu \u015fekildedir:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if ko\u015ful:\n    # Kod blo\u011fu<\/code><\/pre>\n\n\n\n<p>Yukar\u0131daki ifade belirli bir durumun do\u011fru mu yoksa yanl\u0131\u015f m\u0131 oldu\u011funu kontrol eder. E\u011fer do\u011fruysa bir alt sat\u0131rdan yani \u201cKod blo\u011fu\u201d k\u0131sm\u0131ndan \u00e7al\u0131\u015fmaya devam eder. E\u011fer ko\u015ful do\u011fru de\u011filse bu blok atlan\u0131r ve program \u00e7al\u0131\u015fmaya devam eder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sayi = 10\n\nif sayi &gt; 0:\n    print(\"x pozitif bir say\u0131d\u0131r.\")<\/code><\/pre>\n\n\n\n<p>Yukar\u0131daki \u00f6rnekte \u201csayi\u201d ad\u0131n\u0131 verdi\u011fimiz de\u011fer \u201c0\u201d say\u0131s\u0131ndan b\u00fcy\u00fckse alt k\u0131s\u0131mdaki&nbsp;<strong>print(\u201cx pozitif bir say\u0131d\u0131r.\u201d)<\/strong>&nbsp;ifadesi \u00e7al\u0131\u015facakt\u0131r ve ekrana&nbsp;<strong>x pozitif bir say\u0131d\u0131r.<\/strong>&nbsp;yaz\u0131s\u0131 yaz\u0131lacakt\u0131r.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"elif-i\u0307fadesi\">elif \u0130fadesi<\/h3>\n\n\n\n<p>\u201celif\u201d ifadesi, \u201cif\u201d ifadesi ile birlikte kullan\u0131l\u0131r. Burada amac\u0131m\u0131z birden fazla ko\u015ful kontrol etmek istiyorsak \u201celif\u201d ifadesinden faydalan\u0131r\u0131z. Yani ko\u015ful birinci durumda \u201cif\u201d ifadesine bakar do\u011fruysa \u201cif\u201d ifadesindeki ko\u015ful \u00e7al\u0131\u015f\u0131r. De\u011filse \u201celif\u201d blo\u011fundaki ifade \u00e7al\u0131\u015f\u0131r. E\u011fer \u201cif\u201d ve \u201celif\u201d do\u011fru de\u011filse o zaman en son olarak \u201celse\u201d blo\u011funa ge\u00e7er. A\u015fa\u011f\u0131daki \u00f6rnekte bu konuyu a\u00e7\u0131klayal\u0131m:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sayi = 10\n\nif x &gt; 0:\n    print(\"sayi pozitif bir say\u0131d\u0131r.\")\nelif x &lt; 0:\n    print(\"sayi negatif bir say\u0131d\u0131r.\")\nelse:\n    print(\"sayi s\u0131f\u0131rd\u0131r.\")<\/code><\/pre>\n\n\n\n<p>Yukar\u0131daki \u00f6rnekte g\u00f6r\u00fcld\u00fc\u011f\u00fc gibi bir say\u0131 ya s\u0131f\u0131rdan b\u00fcy\u00fckt\u00fcr ya da k\u00fc\u00e7\u00fckt\u00fcr. E\u011fer b\u00fcy\u00fckse ekrana&nbsp;<strong>sayi pozitif bir say\u0131d\u0131r.<\/strong>&nbsp;ifadesi yaz\u0131lacakt\u0131r. De\u011filse&nbsp;<strong>sayi negatif bir say\u0131d\u0131r.<\/strong>&nbsp;ifadesi yaz\u0131lacakt\u0131r. E\u011fer bunlar\u0131n hi\u00e7birisi ise say\u0131m\u0131z o zaman tek bir se\u00e7enek kal\u0131yor o da \u201celse\u201d ko\u015fulu yani&nbsp;<strong>sayi s\u0131f\u0131rd\u0131r.<\/strong>&nbsp;Buradaki \u201cif\u201d de\u011filse olan ko\u015ful \u201celif\u201d ile sa\u011flan\u0131r.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"else-i\u0307fadesi\">else \u0130fadesi<\/h3>\n\n\n\n<p>\u201celse\u201d ifadesi bir \u201cif\u201d veya \u201celif\u201d ifadesinden sonra kullan\u0131l\u0131r. \u201celse\u201d kullan\u0131lmas\u0131ndaki ama\u00e7 yukardaki ko\u015fullar\u0131n yani \u201cif\u201d ve \u201celif\u201d ko\u015fullar\u0131n\u0131n hi\u00e7birisi do\u011fru de\u011filse art\u0131k sadece tek se\u00e7enek kal\u0131yor o da \u201celse\u201d demek oluyor. Her zaman \u201cif\u201d sonra \u201celif\u201d en son \u201celse\u201d gelecek diye bir kural yoktur. \u201celif\u201d olmadan direkt olarak \u201cif\u201d ifadesinden sonra da \u201celse\u201d gelebilir.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sayi = 10\n\nif x &gt; 0:\n    print(\"sayi pozitif bir say\u0131d\u0131r.\")\nelse:\n    print(\"sayi s\u0131f\u0131rd\u0131r veya negatiftir.\")<\/code><\/pre>\n\n\n\n<p>Yukar\u0131daki \u00f6rnekte oldu\u011fu \u015fekliyle de kullan\u0131labilir. E\u011fer \u201cif\u201d do\u011fru ise alt\u0131ndaki&nbsp;<strong>print(\u201csayi pozitif bir say\u0131d\u0131r.\u201d)<\/strong>&nbsp;ifadesi \u00e7al\u0131\u015facakt\u0131r. De\u011filse direkt olarak \u201celse\u201d ko\u015fulu \u00e7al\u0131\u015facakt\u0131r ve&nbsp;<strong>print(\u201csayi s\u0131f\u0131rd\u0131r veya negatiftir.\u201d)<\/strong>&nbsp;ifadesi \u00e7al\u0131\u015facakt\u0131r.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python yaz\u0131l\u0131m diline yeni ba\u015fl\u0131yorsan\u0131z \u00f6\u011frenmeniz gereken en \u00f6nemli konulardan birisi de if-elif-else konusudur. Di\u011fer yaz\u0131l\u0131m dillerinde de bu konu olduk\u00e7a \u00f6nemlidir. Bu ifadeler program\u0131m\u0131zda [&#8230;]<\/p>\n","protected":false},"author":3,"featured_media":453,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[11,10,8,9],"class_list":["post-32","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-bilisim","tag-kodlama","tag-python","tag-yazilim"],"_links":{"self":[{"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/posts\/32","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/comments?post=32"}],"version-history":[{"count":2,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/posts\/32\/revisions"}],"predecessor-version":[{"id":44,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/posts\/32\/revisions\/44"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/media\/453"}],"wp:attachment":[{"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/media?parent=32"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/categories?post=32"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.facadium.com.tr\/blog\/wp-json\/wp\/v2\/tags?post=32"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}