<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>比較演算子 - プログラミングで遊ブログ</title>
	<atom:link href="https://lemon818.com/tag/%E6%AF%94%E8%BC%83%E6%BC%94%E7%AE%97%E5%AD%90/feed/" rel="self" type="application/rss+xml" />
	<link>https://lemon818.com</link>
	<description>現役システムエンジニアが趣味でプログラミングする自由気ままなブログ</description>
	<lastBuildDate>Mon, 20 Jul 2020 13:14:12 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/>	<item>
		<title>【Python】if文で使う比較演算子まとめ（大きい・小さい、以上・以下、等しい、含む）</title>
		<link>https://lemon818.com/python-enzanshi/</link>
		
		<dc:creator><![CDATA[Take]]></dc:creator>
		<pubDate>Mon, 20 Jul 2020 11:45:31 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[大きい]]></category>
		<category><![CDATA[小さい]]></category>
		<category><![CDATA[比較演算子]]></category>
		<category><![CDATA[等しい]]></category>
		<guid isPermaLink="false">https://lemon818.com/?p=4917</guid>

					<description><![CDATA[どーもTakeです。 この記事では、Pythonで if文で使う「比較演算子」について簡単に解説します。 &#160; if文は2つの値を比較する条件式の構文ですが、 値を比較する際に「比較演算子」という演算子を使う必要…]]></description>
										<content:encoded><![CDATA[<p>どーもTakeです。</p>
<p>この記事では、Pythonで if文で使う「比較演算子」について簡単に解説します。</p>
<p>&nbsp;</p>
<p>if文は2つの値を比較する条件式の構文ですが、</p>
<p>値を比較する際に「比較演算子」という演算子を使う必要があります。</p>
<p>&nbsp;</p>
<div style="width: 100%; overflow-y: scroll;">
<table style="border-collapse: collapse; width: 100%;">
<tbody>
<tr>
<td style="width: 33.3333%; background-color: #060a69; text-align: center;"><span style="color: #ffffff;"><strong>演算子</strong></span></td>
<td style="width: 33.3333%; background-color: #060a69; text-align: center;"><span style="color: #ffffff;"><strong>例</strong></span></td>
<td style="width: 33.3333%; background-color: #060a69; text-align: center;"><span style="color: #ffffff;"><strong>意味</strong></span></td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" width="80" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>==</strong></td>
<td width="84" style="width: 33.3333%; text-align: center;">x == y</td>
<td width="235" style="width: 33.3333%; text-align: center;">x と y は等しい</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>!=</strong></td>
<td style="width: 33.3333%; text-align: center;">x != y</td>
<td style="width: 33.3333%; text-align: center;">x と y は等しくない</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>&gt;</strong></td>
<td style="width: 33.3333%; text-align: center;">x &gt; y</td>
<td style="width: 33.3333%; text-align: center;">x は y より大きい</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>&lt;</strong></td>
<td style="width: 33.3333%; text-align: center;">x &lt; y</td>
<td style="width: 33.3333%; text-align: center;">x は y より小さい</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>&gt;=</strong></td>
<td style="width: 33.3333%; text-align: center;">x &gt;= y</td>
<td style="width: 33.3333%; text-align: center;">x は y 以上（等しいか大きい）</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>&lt;=</strong></td>
<td style="width: 33.3333%; text-align: center;">x &lt;= y</td>
<td style="width: 33.3333%; text-align: center;">x は y 以下（等しいか小さい）</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>in</strong></td>
<td style="width: 33.3333%; text-align: center;">x in y</td>
<td style="width: 33.3333%; text-align: center;">x は y に含まれる</td>
</tr>
<tr height="25" style="height: 18.75pt;">
<td height="25" style="height: 18.75pt; width: 33.3333%; background-color: #fffbdb; text-align: center;"><strong>not</strong></td>
<td style="width: 33.3333%; text-align: center;">x not in y</td>
<td style="width: 33.3333%; text-align: center;">x は y に含まれない</td>
</tr>
</tbody>
</table>
</div>
<p>&nbsp;</p>
<p>この記事では上記の「比較演算子」を<strong>「if文」のソースコードを例に</strong><span style="background-color: #ffffff; color: #0000ff;"><strong>具体的に</strong></span>説明します。</p>
<p>&nbsp;</p>
<div class="sc_frame_wrap block blue">
<div class="sc_frame_title">この記事でわかること！</div>
<div class="sc_frame ">
<div class="sc_frame_text">
<div class="sc_designlist ol square solid blue">
<ol>
<li>比較演算子の「等しい」「等しくない」</li>
<li>比較演算子の「大きい」「小さい」</li>
<li>比較演算子の「以上」「以下」</li>
<li>比較演算子の「含まれる」「含まれない」</li>
</ol>
</div>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>※ if文について詳しく知りたい人はこちらの記事も参考にどうぞ！</p>
<div class="sc_getpost"><a class="clearfix" href="https://lemon818.com/python-if/" ><div class="sc_getpost_thumb post-box-thumbnail__wrap"><img decoding="async" src="https://lemon818.com/wp/wp-content/uploads/2020/07/if_1595032396-150x150.jpg" width="150" height="150" alt="【Python】if文、else if（elif）文など条件分岐の書き方（初心者向け）"></div><div class="title">【Python】if文、else if（elif）文など条件分岐の書き方（初心者向け）</div><div class="date">2020.7.18</div><div class="substr">どーもTakeです。 この記事では、Pythonで条件分岐の構文である「if」文と「else if（elif）文」と「else文」について 初心者でも簡単に解説します。  Pythonの条件分岐式は大きく3つあります。 if文・・・基本の条件式 elif文・・・if文以外の条件 else文・・・if...</div></a></div>
<p>&nbsp;</p>
<h2>比較演算子の「等しい」「等しくない」</h2>
<p>Python の比較演算子で「等しい」「等しくない」を表現する場合、下記のように示します。</p>
<div class="sc_frame_wrap blue">
<div class="sc_frame ">
<div class="sc_designlist ol square solid blue">
<ol>
<li>x == y　・・・ x と y は等しい</li>
<li>x != y　・・・ x と y は等しくない</li>
</ol>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>比較演算子で「等しい」とする場合の具体的なソースコードで説明します。</p>
<p>x = 3、y = 3 は等しいため、if 文の条件式で「x == y」とすることで「等しい」という表示されます。</p><pre class="crayon-plain-tag">x = 3
y = 3

if x == y :
    print("等しい")
else:
    print("等しくない")

&gt;&gt;&gt; 実行結果
等しい</pre><p>
&nbsp;</p>
<p>比較演算子で「等しくない」とする場合の具体的なソースコードで説明します。</p>
<p>x = 3、y = 2 は等しくないため、if 文の条件式で「x != y」とすることで「等しくない」という表示されます。</p><pre class="crayon-plain-tag">x = 3
y = 2

if x != y :
    print("等しくない")
else:
    print("等しい")

&gt;&gt;&gt; 実行結果
等しくない</pre><p>
&nbsp;</p>
<h2>比較演算子の「大きい」「小さい」</h2>
<p>Python の比較演算子で「大きい」「小さい」を表現する場合、下記のように示します。</p>
<div class="sc_frame_wrap blue">
<div class="sc_frame ">
<div class="sc_designlist ol square solid blue">
<ol>
<li>x &gt; y　・・・ x は y より大きい</li>
<li>x &lt; y　・・・ x は y より小さい</li>
</ol>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>比較演算子で「大きい」とする場合の具体的なソースコードで説明します。</p>
<p>x = ５、y = 3 とする場合、if 文の条件式で「x ＞ y」とすることで「x は y より大きい」という表示されます。</p><pre class="crayon-plain-tag">x = 5
y = 3

if x &gt; y :
    print("大きい")
else:
    print("小さい")

&gt;&gt;&gt; 実行結果
大きい</pre><p>
&nbsp;</p>
<p>比較演算子で「小さい」とする場合の具体的なソースコードで説明します。</p>
<p>x = 3、y = 5 とする場合、if 文の条件式で「x ＜ y」とすることで「x は y より小さい」という表示されます。</p><pre class="crayon-plain-tag">x = 3
y = 5

if x &lt; y :
    print("小さい")
else:
    print("大きい")

&gt;&gt;&gt; 実行結果
小さい</pre><p>
&nbsp;</p>
<h2>比較演算子の「以上」「以下」</h2>
<p>Python の比較演算子で「以上」「以下」を表現する場合、下記のように示します。</p>
<div class="sc_frame_wrap blue">
<div class="sc_frame ">
<div class="sc_designlist ol square solid blue">
<ol>
<li>x &gt;= y　・・・ x は y 以上（等しいか大きい）</li>
<li>x &lt;= y　・・・ x は y 以下（等しいか小さい）</li>
</ol>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>比較演算子で「以上」とする場合の具体的なソースコードで説明します。</p>
<p>x = 5、y = 3 とする場合、</p>
<p>if 文の条件式で「x &gt;= y」とすることで「 x は y 以上（等しいか大きい）」という表示されます。</p><pre class="crayon-plain-tag">x = 5
y = 3

if x &gt;= y :
    print("x は y 以上（等しいか大きい）")
else:
    print("x は y より小さい")

&gt;&gt;&gt; 実行結果
x は y 以上（等しいか大きい）</pre><p>
&nbsp;</p>
<p>比較演算子で「以下」とする場合の具体的なソースコードで説明します。</p>
<p>x = 3、y = 5 とする場合、</p>
<p>if 文の条件式で「x &lt;= y」とすることで「 x は y 以下（等しいか小さい）」という表示されます。</p><pre class="crayon-plain-tag">x = 3
y = 5

if x &lt;= y :
    print("x は y 以下（等しいか小さい）")
else:
    print("x は y より大きい")

&gt;&gt;&gt; 実行結果
x は y 以下（等しいか小さい）</pre><p>
&nbsp;</p>
<h2>比較演算子の「含まれる」「含まれない」</h2>
<p>Python の比較演算子で「含まれる」「含まれない」を表現する場合、下記のように示します。</p>
<div class="sc_frame_wrap blue">
<div class="sc_frame ">
<div class="sc_designlist ol square solid blue">
<ol>
<li>x in y　・・・ x が y に含まれる</li>
<li>x not in y　・・・ x が y に含まれない</li>
</ol>
</div>
</div>
</div>
<p>&nbsp;</p>
<p>これは、定義した<strong>配列に要素が含まれるか、含まれないか</strong>といった場合によく使われる演算子です。</p>
<p>&nbsp;</p>
<p>比較演算子で「含まれる」とする場合の具体的なソースコードで説明します。</p>
<p>x = "A"、y = ["A","B","C"] とする場合、"A"という文字列は配列["A","B","C"] に存在する（含まれる）ため</p>
<p>if 文の条件式で「x in y」とすることで「含む」という表示されます。</p><pre class="crayon-plain-tag">x = "A"
y = ["A","B","C"]

if x in y :
    print("含まれる")
else:
    print("含まれない")

&gt;&gt;&gt; 実行結果
含まれる</pre><p>
&nbsp;</p>
<p>比較演算子で「含まれない」とする場合の具体的なソースコードで説明します。</p>
<p>x = "D"、y = ["A","B","C"] とする場合、"D"という文字列は配列["A","B","C"] に存在しない（含まれない）ため</p>
<p>if 文の条件式で「x not in y」とすることで「含まれない」という表示されます。</p><pre class="crayon-plain-tag">x = "D"
y = ["A","B","C"]

if x not in y :
    print("含まれない")
else:
    print("含まれる")

&gt;&gt;&gt; 実行結果
含まない</pre><p>
&nbsp;</p>
<h2>最後に</h2>
<p>いかがでしたでしょうか？</p>
<p>この記事では、Pythonで if文で使う「比較演算子」について解説しました。</p>
<p>&nbsp;</p>
<p>この記事を参考にぜひ比較演算子をマスターしていただければと思います。</p>
<p>ではでは。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
