{ "cells": [ { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Mantıksal Bağlaçlar\n", "Mantıksal bağlaçlar daha çok karşılaştırma işlemini kontrol ettiğimiz zamanlarda kullanılır. Bu konuda bunları öğrenmeye çalışacağız.\n", "\n", "### and Operatörü" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Bu mantıksal bağlaç, bütün karşılaştırma işlemlerinin sonucunun **True** olmasına bakar. Bağlanan karşılaştırma işlemlerinin hepsinin kendi içinde sonucu **True** ise genel sonuç **True** , diğer durumlarda ise sonuç **False** çıkar. Kullanımı şu şekildedir.\n", "\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 < 2 and \"Murat\" == \"Murat\"" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 > 3 and \"Murat\" == \"Murat\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 == 2 and 3.14 < 2.54 and \"Elma\" != \"Armut\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "İşlemlerin birinin bile sonucu **False** ise genel işlemin sonucu **False** çıkmaktadır.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### or Operatörü\n", "Bu mantıksal bağlaç, bütün karşılaştırma işlemlerinin sonuçlarından **en az birinin True** olmasına bakar. Bağlanan karşılaştırma işlemlerinin **en az birinin True** olmasında genel sonuç **True** , diğer durumlarda ise sonuç **False** çıkar. Kullanımı şu şekildedir.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1 < 2 or \"Murat\" != \"Murat\"" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 > 3 or \"Murat\" != \"Murat\"" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "2 > 3 or \"Murat\" != \"Murat\" or 3.14 < 4.32" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### not operatörü\n", "\n", "*not* operatörü aslında bir mantıksal bağlaç değildir. Bu operatör sadece bir mantıksal değeri veya karşılaştırma işlemininin tam tersi sonuca çevirir. Yani, not operatörü **True** olan bir sonucu **False** , **False** olan bir sonucu **True** sonucuna çevirir. Kullanımı şu şekildedir.\n", "\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "False" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "not 2 == 2" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "not \"Python\" == \"Php\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Operatörleri Beraber Kullanma\n", "\n", "Burada gördüğümüz 3 operatörü beraber kullanmak karmaşıklığa yol açacağı için, *parantez* kullanabiliriz. \n" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "not (2.14 > 3.49 or ( 2 != 2 and \"Murat\" == \"Murat\"))" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\"Araba\" < \"Zula\" and ( \"Bebek\" < \"Çoçuk\" or (not 14 ))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }