<?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>文法  |  Pythonアカデミア</title>
	<atom:link href="https://arika-blog.com/category/python/grammar-python/feed/" rel="self" type="application/rss+xml" />
	<link>https://arika-blog.com</link>
	<description>Pythonの基礎が学べる</description>
	<lastBuildDate>Fri, 30 Jan 2026 20:49:09 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://arika-blog.com/wp-content/uploads/2022/11/cropped-icon-12-32x32.png</url>
	<title>文法  |  Pythonアカデミア</title>
	<link>https://arika-blog.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<atom:link rel='hub' href='https://arika-blog.com/?pushpress=hub'/>
	<item>
		<title>【Python】文字列（str）を結合するjoinメソッドについて解説</title>
		<link>https://arika-blog.com/python-join/</link>
					<comments>https://arika-blog.com/python-join/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Thu, 30 May 2024 21:47:47 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<category><![CDATA[関数]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3912</guid>

					<description><![CDATA[Pythonは＋演算子などで文字列を連結することができますが、iterableオブジェクトについてはjoinメソッドを使って連結することができます。本記事ではそんなjoinメソッドの使い方と注意点を解説します。 Pyth [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonは＋演算子などで文字列を連結することができますが、iterableオブジェクトについてはjoinメソッドを使って連結することができます。本記事ではそんなjoinメソッドの使い方と注意点を解説します。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">joinメソッドの使い方</h2>



<p>iterable中の文字列を結合した文字列を返します。要素間のセパレータは、このメソッドを提供する文字列です。</p>



<p><a href="https://docs.python.org/ja/3/library/stdtypes.html#str.join">組み込み型 str.join() ー Python公式ドキュメント</a></p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>str.join(iterable)</p>
</div></div>



<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-11 sbs-flat sbp-l sbis-sn cf block-box"><div class="speech-person"><figure class="speech-icon"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/2025/11/icon-1-1-1.png" alt="" class="speech-icon-image"/></figure><div class="speech-name"></div></div><div class="speech-balloon">
<p>iterable（反復可能体）とは、for文で繰り返すことができるものです。リストやタプルなど。</p>
</div></div>



<script src="https://gist.github.com/arika-python/faf5029e21dfe67b32f15c3d04194e52.js"></script>



<h2 class="wp-block-heading">注意点</h2>



<p>iterableにbytesオブジェクトのような非文字列の値が存在するなら、TypeErrorが送出されます。</p>



<script src="https://gist.github.com/arika-python/3cd151bfa6bc6be7b6b5d8875cf58ac7.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>joinメソッドについて解説しました。文字列を連結できる便利なメソッドなので、きちんと理解しておきましょう。</p>



<p><strong>関連記事</strong><br><a href="https://arika-blog.com/python-rjust-ljust-center-zfill/">【Python】文字列を揃える方法を解説（右寄せ・中央寄せ・左寄せ）</a><br><a href="https://arika-blog.com/python-len/">【Python】len関数を使って文字列やリストの長さを取得する</a><br><a href="https://arika-blog.com/python-f-string/">【Python】フォーマット済み文字列リテラル(f-string)の使い方</a><br><a href="https://arika-blog.com/python-r-string/">【Python】raw文字列の使い方（エスケープシーケンスを無効化）</a></p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-join/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】文字列を揃える方法を解説（右寄せ・中央寄せ・左寄せ）</title>
		<link>https://arika-blog.com/python-rjust-ljust-center-zfill/</link>
					<comments>https://arika-blog.com/python-rjust-ljust-center-zfill/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Sat, 04 May 2024 14:26:42 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<category><![CDATA[関数]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3826</guid>

					<description><![CDATA[Pythonには文字列を寄せることができる、str.rjust()、str.center()、str.ljust()というメソッドがあります。本記事ではそれぞれの使い方と性質について解説します。 Python 基礎文法の [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonには文字列を寄せることができる、str.rjust()、str.center()、str.ljust()というメソッドがあります。本記事ではそれぞれの使い方と性質について解説します。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">str.rjust()</h2>



<p>widthの長さをもつ右寄せした文字列を返します。パディングにはfillcharで指定された文字(デフォルトではASCIIスペース)が使われます。widthがlen(s)以下の場合、元の文字列が返されます。</p>



<p><a href="https://docs.python.org/ja/3/library/stdtypes.html#str.rjust">組み込み型 str.rjust() ー Python公式ドキュメント</a></p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>str.rjust(width[, fillchar])</p>
</div></div>



<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-11 sbs-flat sbp-l sbis-sn cf block-box"><div class="speech-person"><figure class="speech-icon"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/2025/11/icon-1-1-1.png" alt="" class="speech-icon-image"/></figure><div class="speech-name"></div></div><div class="speech-balloon">
<p>公式ドキュメントで角括弧が出てくる場合がありますが、これはオプションという意味です</p>
</div></div>



<script src="https://gist.github.com/arika-python/3113659f9d2403c63ed37ac3123e7d59.js"></script>



<h2 class="wp-block-heading">str.ljust()</h2>



<p>長さwidthの左揃えした文字列を返します。パディングは指定されたfillchar(デフォルトではASCIIスペース)を使って行われます。widthがlen(s)以下ならば、元の文字列が返されます。</p>



<p><a href="https://docs.python.org/ja/3/library/stdtypes.html#str.ljust">組み込み型 str.ljust() ー Python公式ドキュメント</a></p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>str.ljust(width[, fillchar])</p>
</div></div>



<script src="https://gist.github.com/arika-python/83426c5e62f4e06ef2687c301518d71b.js"></script>



<h2 class="wp-block-heading">str.center()</h2>



<p>widthの長さをもつ中央寄せされた文字列を返します。パディングにはfillcharで指定された値(デフォルトではASCIIスペース)が使われます。widthがlen(s)以下なら元の文字列が返されます。</p>



<p><a href="https://docs.python.org/ja/3/library/stdtypes.html#str.center">組み込み型 str.center() ー Python公式ドキュメント</a></p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>str.center(width[, fillchar])</p>
</div></div>



<script src="https://gist.github.com/arika-python/0f018c776e2d0ebbd4932f37f0a4d91f.js"></script>



<h2 class="wp-block-heading">符号付きで0埋めする場合は（主題から逸れます）</h2>



<p>長さがwidthになるようASCII&#8217;0&#8217;で左詰めした文字列のコピーを返します。先頭が符号接頭辞(&#8216;+&#8217;/&#8217;-&#8216;)だった場合、&#8217;0&#8217;は符号の前ではなく後に挿入されます。widthがlen(s)以下の場合元の文字列を返します。</p>



<p><a href="https://docs.python.org/ja/3/library/stdtypes.html#str.zfill">組み込み型 str.zfill() ー Python公式ドキュメント</a></p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>str.zfill(width)</p>
</div></div>



<script src="https://gist.github.com/arika-python/e3bb5f4caab7960c39c3dc9df991256f.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>文字列を寄せる方法について解説しました。Pythonコードの可読性向上に活用しましょう。</p>



<p><strong>関連記事</strong><br><a href="https://arika-blog.com/python-join/">【Python】文字列（str）を結合するjoinメソッドについて解説</a><br><a href="https://arika-blog.com/python-len/">【Python】len関数を使って文字列やリストの長さを取得する</a><br><a href="https://arika-blog.com/python-f-string/">【Python】フォーマット済み文字列リテラル(f-string)の使い方</a><br><a href="https://arika-blog.com/python-r-string/">【Python】raw文字列の使い方（エスケープシーケンスを無効化）</a></p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-rjust-ljust-center-zfill/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】セイウチ演算子(:=)の使い方を解説</title>
		<link>https://arika-blog.com/python-walrus-operator/</link>
					<comments>https://arika-blog.com/python-walrus-operator/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Thu, 02 May 2024 01:24:28 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3819</guid>

					<description><![CDATA[Pythonには変数の代入と使用を同時にできるセイウチ演算子というものがあります。本記事ではそんなセイウチ演算子について解説します。 Python 基礎文法の教科書を執筆しました！ セイウチ演算子の使い方 セイウチ演算子 [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonには変数の代入と使用を同時にできるセイウチ演算子というものがあります。本記事ではそんなセイウチ演算子について解説します。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">セイウチ演算子の使い方</h2>



<p>セイウチ演算子は等号「=」の前にコロン「:」をつけます。Python3.8以降で使用することができます。</p>



<p><a href="https://docs.python.org/ja/3/whatsnew/3.8.html#assignment-expressions">What&#8217;s New In Python 3.8 ー 代入式</a><br><a href="https://docs.python.org/ja/dev/faq/design.html#why-can-t-i-use-an-assignment-in-an-expression">デザインとFAQ ー 式中で代入できないのはなぜですか？</a></p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>変数 := 式</p>
</div></div>



<p>コードをスッキリ書くことができます。</p>



<script src="https://gist.github.com/arika-python/8b9dbdd5ac44d1c247c879503e7b03ad.js"></script>



<p>取得したデータに対して分岐させるときなどに便利です。</p>



<h2 class="wp-block-heading">注意点</h2>



<p>代入して比較する際はセイウチ演算子の範囲をカッコで囲む必要があります。</p>



<script src="https://gist.github.com/arika-python/aa4d1031d45b185d6260d89b383707c1.js"></script>



<p>カッコで囲まないと大小比較の結果が代入されるので注意しましょう。（セイウチ演算子の優先順位が演算子の中で一番低いため）</p>



<p>曖昧さやユーザーの混乱を避けるために、代入式が許可されていない場所があります。例えば、式は文が書ける位置に記述できますが、代入式はエラーになります。</p>



<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-11 sbs-flat sbp-l sbis-sn cf block-box"><div class="speech-person"><figure class="speech-icon"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/2025/11/icon-1-1-1.png" alt="" class="speech-icon-image"/></figure><div class="speech-name"></div></div><div class="speech-balloon">
<p>ただし、かっこで代入式を囲むと記述することができます</p>
</div></div>



<script src="https://gist.github.com/arika-python/c2e7f50a03773a24891c9cf334e811bf.js"></script>



<p>詳しくはpep572をご確認ください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://peps.python.org/pep-0572/#exceptional-cases" title="PEP 572 – Assignment Expressions | peps.python.org" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/9274df3cc110da1ab8e804360cf1839e.png" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">PEP 572 – Assignment Expressions | peps.python.org</div><div class="blogcard-snippet external-blogcard-snippet">This is a proposal for creating a way to assign to variables within an expression using the notation NAME := expr.</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://peps.python.org/pep-0572/" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">peps.python.org</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">まとめ</h2>



<p>セイウチ演算子について解説をしました。必ずしも覚える必要はありませんが、スッキリしたコードが書けるので概要は押さえておきましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-walrus-operator/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】isと==の違いを解説</title>
		<link>https://arika-blog.com/python-is-eq/</link>
					<comments>https://arika-blog.com/python-is-eq/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Mon, 18 Mar 2024 21:01:21 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3059</guid>

					<description><![CDATA[Pythonにはオブジェクトの比較ができるisと==（比較演算子）があります。本記事では２つの演算子の特徴と違いを解説します。 Python 基礎文法の教科書を執筆しました！ is演算子 is演算子は2つのオブジェクトが [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonにはオブジェクトの比較ができるisと==（比較演算子）があります。本記事では２つの演算子の特徴と違いを解説します。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">is演算子</h2>



<p>is演算子は2つのオブジェクトが同一であればTrueを返します。判定にはid関数が使われています。</p>



<script src="https://gist.github.com/arika-python/31443664f1d07450b79a06abd3f7c54a.js"></script>



<p><strong>関連記事</strong><br><a href="https://arika-blog.com/python-id/">【Python】識別値を取得できるid関数について解説</a></p>



<h2 class="wp-block-heading">==演算子</h2>



<p>==演算子は値が等しければTrueを返します。<span class="marker-under-blue">識別値が等しいかどうかは関係ありません。</span></p>



<script src="https://gist.github.com/arika-python/cd5accb8956f6a5e2ec47c1c9fa6e8f8.js"></script>



<p>ちなみにa = []、b = []とすると、&nbsp;aとbは異なったリストを参照することが保証されています。</p>



<p>詳しくは以下の記事をご確認ください。<br><a href="https://arika-blog.com/python-mutable-immutable/">【Python】ミュータブルとイミュータブルを理解する</a></p>



<h3 class="wp-block-heading">!=演算子</h3>



<p>!=演算子は値が等しければFalseを返します。</p>



<script src="https://gist.github.com/arika-python/8a1384c4655859b1ab56e60f5db65443.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>isと==について解説しました。2つの違いを理解して、状況に応じて使えるようにしましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><br></p>
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-is-eq/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】sysモジュールについて解説(argv・path・exitなど)</title>
		<link>https://arika-blog.com/python-sys/</link>
					<comments>https://arika-blog.com/python-sys/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Mon, 04 Mar 2024 21:48:54 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<category><![CDATA[モジュール]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3389</guid>

					<description><![CDATA[sysモジュールはコマンドライン引数を受け取ったり、モジュールの検索パスを調べることができます。本記事では、そんなsysモジュールについて解説をします。 Python 基礎文法の教科書を執筆しました！ sysモジュールに [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>sysモジュールはコマンドライン引数を受け取ったり、モジュールの検索パスを調べることができます。本記事では、そんなsysモジュールについて解説をします。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">sysモジュールについて</h2>



<p>sysモジュールは、インタプリタで使用・管理している変数や、インタプリタの動作に深く関連する関数が定義されています。</p>



<p><a href="https://docs.python.org/ja/3/library/sys.html">標準ライブラリ<code>sys</code>&nbsp;&#8212; システムパラメータと関数</a></p>



<h3 class="wp-block-heading">sys.path</h3>



<p>モジュール検索パスはsys.pathで定義されています。</p>



<script src="https://gist.github.com/arika-python/8ad0b4008356ddb6d3f0000566bec604.js"></script>



<p>モジュールの検索パスは以下の順番で記載されています。</p>



<ol class="wp-block-list">
<li>入力されたスクリプトのあるディレクトリ（ファイルの指定がない場合はカレントディレクトリ）</li>



<li>PYTHONPATH</li>



<li>インストールごとのデフォルト</li>
</ol>



<p>PYTHONPATHは自身で設定できる環境変数です。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="1024" src="https://arika-blog.com/wp-content/uploads/2024/03/icon-7-1024x1024.png" alt="" class="wp-image-3396" style="width:373px;height:auto" srcset="https://arika-blog.com/wp-content/uploads/2024/03/icon-7-1024x1024.png 1024w, https://arika-blog.com/wp-content/uploads/2024/03/icon-7-300x300.png 300w, https://arika-blog.com/wp-content/uploads/2024/03/icon-7-150x150.png 150w, https://arika-blog.com/wp-content/uploads/2024/03/icon-7-768x768.png 768w, https://arika-blog.com/wp-content/uploads/2024/03/icon-7-100x100.png 100w, https://arika-blog.com/wp-content/uploads/2024/03/icon-7.png 1200w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p>また、文字列のリストで出力されるため、リストの操作で修正することができます。</p>



<script src="https://gist.github.com/arika-python/d8ce2ac11675d9f151bd21d2866c8445.js"></script>



<div class="wp-block-cocoon-blocks-icon-box common-icon-box block-box memo-box">
<p>list.pop(i)：指定された位置のアイテムをリストから削除し、このアイテムを返す</p>
</div>



<h3 class="wp-block-heading">sys.argv</h3>



<p>スクリプト名と引数群はsysモジュールのargvに割り当てられます。</p>



<p>例えば以下のスクリプト(sys_argv.py)に対して、引数群を与えて実行すると、スクリプト名と引数群が入ったリストを出力します。</p>



<script src="https://gist.github.com/arika-python/44971df74f469ad3d4158644b0770c47.js"></script>



<script src="https://gist.github.com/arika-python/f5049bec2d17f6520e55a816726c5f5b.js"></script>



<div class="wp-block-cocoon-blocks-icon-box common-icon-box block-box alert-box">
<p>sys.argv[0]がスクリプト名になるので注意</p>
</div>



<h3 class="wp-block-heading">sys.builtin_module_names</h3>



<p>sys.builtin_module_namesで標準モジュールの一覧を確認することができます。</p>



<script src="https://gist.github.com/arika-python/6cfacc8743dac4b8f618018ebadd9668.js"></script>



<h3 class="wp-block-heading">sys.stdout</h3>



<p>標準出力(画面)のファイルオブジェクトはsys.stdoutとして参照できます。</p>



<script src="https://gist.github.com/arika-python/78c43f4dc8e4715d3dd87a65e59dbfd5.js"></script>



<div class="wp-block-cocoon-blocks-icon-box common-icon-box block-box information-box">
<p>文字数も同時に出力されます</p>
</div>



<h3 class="wp-block-heading">sys.ps1, sys.ps2</h3>



<p>インタープリタのプライマリプロンプトとセカンダリプロンプトはsys.ps1とsys.ps2で定義されています。</p>



<script src="https://gist.github.com/arika-python/63a68756f0e2b8d57e34e9a42de93613.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>sysモジュールについてまとめました。使用頻度はそこまで多くありませんが、便利な機能もあるので概要は押さえておきましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-sys/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Pythonの可変長引数】*args、**kwargsの違いと使い方を徹底解説！</title>
		<link>https://arika-blog.com/python-args-kwargs/</link>
					<comments>https://arika-blog.com/python-args-kwargs/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Mon, 19 Feb 2024 21:43:24 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3251</guid>

					<description><![CDATA[Pythonには複数の引数を受け取ることができる*argsと**kwargs（可変長引数）があります。本記事ではこれらの違いと性質について解説をします。 関数の基本を確認したい方はこちらの記事をご活用ください。 *arg [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonには複数の引数を受け取ることができる*argsと**kwargs（可変長引数）があります。本記事ではこれらの違いと性質について解説をします。</p>



<p>関数の基本を確認したい方はこちらの記事をご活用ください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939/viewer/ed6a52" title="Pythonの関数定義をマスターしよう！｜【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">Pythonの関数定義をマスターしよう！｜【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet"></div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939/viewer/ed6a52" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">*argsの使い方</h2>



<p>*argsは複数の引数をタプルで受け取ることができます。</p>



<script src="https://gist.github.com/arika-python/ad32e4de46ed2bb854def3b7b7b27ad9.js"></script>



<p>*argsの後ろに仮引数がある場合はキーワード引数で呼び出します。</p>



<script src="https://gist.github.com/arika-python/52ece26aaf77f401caf078c1e83c5972.js"></script>



<h2 class="wp-block-heading">**kwargsの使い方</h2>



<p>**kwargsは複数の引数を辞書で受け取ることができます。</p>



<script src="https://gist.github.com/arika-python/043c6cdb786eb2500508bd902e8ca6e4.js"></script>



<p>仮引数に対応するキーワードを除いたすべてのキーワード引数が入ります。</p>



<script src="https://gist.github.com/arika-python/ddff88e596173dd906cb0df3538420d7.js"></script>



<p>**kwargsは最後でのみ定義できます。</p>



<script src="https://gist.github.com/arika-python/f5b8844d1062de731fea3cd82045a8ca.js"></script>



<h2 class="wp-block-heading">*argsと**kwargsの性質</h2>



<p>*argsと**kwargsには以下の性質があります。</p>



<h3 class="wp-block-heading">*argsと**kwargsは同時に使える</h3>



<p>*argsと**kwargsは同時に使うことができます。</p>



<script src="https://gist.github.com/arika-python/ee15b40e7365c1f7bdfd87d85faf335c.js"></script>



<h3 class="wp-block-heading">名前に決まりはない</h3>



<p>*args、**kwargsとしなくても問題ありません。</p>



<script src="https://gist.github.com/arika-python/f12de36b563cca78b28d2401b8f2cfd7.js"></script>



<h3 class="wp-block-heading">引数がないとき</h3>



<p>引数無しで呼び出すと空のタプルと空の辞書になります。</p>



<script src="https://gist.github.com/arika-python/ae187d0dd5004388bc86f974ebf3e6ac.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>*argsと**kwargsを使うことで複数の引数を扱うことができます。コーディングの幅を広げるのに活用しましょう。</p>



<p><strong>関連記事</strong><br><a href="https://arika-blog.com/python-function-annotations/">【Python】関数アノテーションの使い方</a></p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-args-kwargs/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】位置専用引数とキーワード専用引数の使い方</title>
		<link>https://arika-blog.com/python-positional-keyword-only/</link>
					<comments>https://arika-blog.com/python-positional-keyword-only/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Mon, 29 Jan 2024 21:59:56 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3057</guid>

					<description><![CDATA[Pythonには位置専用引数とキーワード専用引数という特殊引数が存在します。本記事では２つの引数の使い方と注意点を解説します。 Python 基礎文法の教科書を執筆しました！ 位置専用引数 位置専用引数は/より前に置かれ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonには位置専用引数とキーワード専用引数という特殊引数が存在します。本記事では２つの引数の使い方と注意点を解説します。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">位置専用引数</h2>



<p>位置専用引数は<strong>/</strong>より前に置かれます。</p>



<script src="https://gist.github.com/arika-python/592fd024236a372207f444394987e33d.js"></script>



<h3 class="wp-block-heading">位置引数と任意個数のキーワード引数の衝突を防げる</h3>



<p>位置専用引数を活用することで、位置引数と任意個数のキーワード引数の衝突を防げます。</p>



<script src="https://gist.github.com/arika-python/01bec9bb91a37108688dc7a5840063d3.js"></script>



<h2 class="wp-block-heading">キーワード専用引数</h2>



<p>キーワード専用引数は<strong>*</strong>より後ろに置かれます。</p>



<script src="https://gist.github.com/arika-python/984671458725f8cc8d50b13400bf9b31.js"></script>



<h2 class="wp-block-heading">併用することも可能</h2>



<p>位置専用引数とキーワード専用引数は併用することも可能です。</p>



<script src="https://gist.github.com/arika-python/5e8092d9c3c4ccb85286400460adff24.js"></script>



<h2 class="wp-block-heading">自分で使わなくてもドキュメントに出てくるので注意</h2>



<p>自身が使わないとしてもドキュメントに出てくる場合があります。概要は押さえて、読めるようにしておきましょう。</p>



<figure class="wp-block-image size-large is-resized"><img loading="lazy" decoding="async" width="1024" height="247" src="https://arika-blog.com/wp-content/uploads/2024/01/35e6c5557168cda1a061ac15d1053d0f-1024x247.png" alt="" class="wp-image-3082" style="width:840px;height:auto" srcset="https://arika-blog.com/wp-content/uploads/2024/01/35e6c5557168cda1a061ac15d1053d0f-1024x247.png 1024w, https://arika-blog.com/wp-content/uploads/2024/01/35e6c5557168cda1a061ac15d1053d0f-300x72.png 300w, https://arika-blog.com/wp-content/uploads/2024/01/35e6c5557168cda1a061ac15d1053d0f-768x185.png 768w, https://arika-blog.com/wp-content/uploads/2024/01/35e6c5557168cda1a061ac15d1053d0f.png 1027w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /><figcaption class="wp-element-caption">引用：<a href="https://docs.python.org/ja/3/library/functions.html">https://docs.python.org/ja/3/library/functions.html</a></figcaption></figure>



<h2 class="wp-block-heading">まとめ</h2>



<p>位置専用引数とキーワード専用引数は可読性をあげるのに有用です。必要に応じて使えるようにしましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-positional-keyword-only/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】ミュータブルとイミュータブルを理解する</title>
		<link>https://arika-blog.com/python-mutable-immutable/</link>
					<comments>https://arika-blog.com/python-mutable-immutable/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Sat, 20 Jan 2024 16:42:48 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=2989</guid>

					<description><![CDATA[Pythonではオブジェクトによってミュータブルとイミュータブルに分類されます。本記事ではこの2つの違いと注意点について解説します。 Python 基礎文法の教科書を執筆しました！ ミュータブルとは値を変更できるオブジェ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p id="78CBFB85-B3BF-4BFD-A9C6-0C71C79131AA">Pythonではオブジェクトによってミュータブルとイミュータブルに分類されます。<br>本記事ではこの2つの違いと注意点について解説します。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">ミュータブルとは値を変更できるオブジェクトのこと</h2>



<p>ミュータブルとは値を変更できるオブジェクトのことです。<br>主な型はリストや辞書などがあります。</p>



<script src="https://gist.github.com/arika-python/540e293cd4d5f16f97dc5ad9fbe08fdc.js"></script>



<h2 class="wp-block-heading">イミュータブルとは値を変更できないオブジェクトのこと</h2>



<p>イミュータブルとは値を変更できないオブジェクトのことです。<br>主な型はタプルや文字列などがあります。</p>



<script src="https://gist.github.com/arika-python/883a65141d4f19bc0dbe56d03e40788a.js"></script>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>なぜPythonの文字列はイミュータブルなのですか？</strong></p>



<p>これにはいくつかの利点があります。</p>



<p>一つはパフォーマンスです。文字列がイミュータブルなら、生成時に領域を割り当てることができるので、必要な記憶域は固定されて、変更されません。これはタプルとリストを区別する理由の一つでもあります。</p>



<p>他の利点は、Python の文字列は数と同じくらい &#8220;基本的&#8221; なものと考えられることです。8 という値を他の何かに変える手段が無いように、文字列 &#8220;eight&#8221; を他の何かに変える手段も無いのです。</p>
<cite><a href="https://docs.python.org/ja/3.6/faq/design.html#why-are-python-strings-immutable">デザインと歴史 FAQ ー Python公式ドキュメント</a></cite></blockquote>



<h2 class="wp-block-heading">id関数を使って確認する</h2>



<p>ミュータブルなオブジェクトは、要素の追加・削除などをしてもIDは変わりません。またイミュータブルなオブジェクトは、同じIDのまま値を変更することはできません。</p>



<script src="https://gist.github.com/arika-python/c0246f8df1dab0a728e127943c14a473.js"></script>



<p><strong>関連記事</strong><br><a href="https://arika-blog.com/python-id/">【Python】識別値を取得できるid関数について解説</a></p>



<h2 class="wp-block-heading">ミュータブル・イミュータブルオブジェクトの注意点</h2>



<p>ミュータブル・イミュータブルオブジェクトの注意点を解説します。</p>



<h3 class="wp-block-heading">同じオブジェクトを参照する時としない時がある</h3>



<p>Pythonにおいてミュータブルオブジェクトは同じ値を持ったとき、違うオブジェクトを参照することが保証されていますが、イミュータブルオブジェクトは同じオブジェクトを参照するときもあるし、そうでないときもあります。</p>



<p>つまり、a = 1、b = 1としたとき、a と b は値 1 を持つ同じオブジェクトを参照する時としないときがあります。しかし、c = []、d = [] とすると、 c と d は異なったリストを参照することが保証されているということです。</p>



<p>詳細はこちらをご確認ください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://docs.python.org/ja/3.9/reference/datamodel.html" title="3. &#12487;&#12540;&#12479;&#12514;&#12487;&#12523; &#8212; Python 3.9.24 &#12489;&#12461;&#12517;&#12513;&#12531;&#12488;" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://s.wordpress.com/mshots/v1/https%3A%2F%2Fdocs.python.org%2Fja%2F3.9%2Freference%2Fdatamodel.html?w=160&#038;h=90" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">3. &#12487;&#12540;&#12479;&#12514;&#12487;&#12523; &#8212; Python 3.9.24 &#12489;&#12461;&#12517;&#12513;&#12531;&#12488;</div><div class="blogcard-snippet external-blogcard-snippet"></div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://docs.python.org/ja/3.9/reference/datamodel.html" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">docs.python.org</div></div></div></div></a>
</div>



<h3 class="wp-block-heading">デフォルト値は1回しか評価されない</h3>



<p>関数のデフォルト値は1回しか評価されません。<br>よって、ミュータブルオブジェクトの場合に影響を受けます。</p>



<script src="https://gist.github.com/arika-python/eaede1ed34e84f0c46188026093da518.js"></script>



<p>1回しか評価されないのでリストに値が追加されていく形になります。</p>



<div class="wp-block-cocoon-blocks-icon-box common-icon-box block-box memo-box">
<p>デフォルト値はnum_lists = []の部分です。関数を呼び出したときに引数を与えないとデフォルト値が使用されます。</p>
</div>



<p>これを避けたい場合は関数の中で空のリストを生成します。</p>



<script src="https://gist.github.com/arika-python/1cb122fac6abc5e4f4edf8e5f44a739f.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>Pythonにおけるミュータブルとイミュータブルの違いを解説しました。それぞれの性質をきちんと理解することで、意図しない動作を回避できます。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-mutable-immutable/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】予約語の確認方法について（keywordモジュール）</title>
		<link>https://arika-blog.com/python-reserved-word/</link>
					<comments>https://arika-blog.com/python-reserved-word/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Sat, 20 Jan 2024 15:12:04 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<category><![CDATA[モジュール]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=2992</guid>

					<description><![CDATA[Pythonには予約語という既に役割が決まっている単語が存在します。電話番号で言うと、110番や119番などが予約語にあたります。本記事ではkeywordモジュールを使った予約語の確認方法や予約語の注意点について解説をし [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonには予約語という既に役割が決まっている単語が存在します。電話番号で言うと、110番や119番などが予約語にあたります。本記事ではkeywordモジュールを使った予約語の確認方法や予約語の注意点について解説をします。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">予約語の確認方法</h2>



<p>Pythonの予約語と言えば、if・for・Ture・def・classなどが挙げられますが、keywordモジュールを使って確認することができます。</p>



<p><a href="https://docs.python.org/ja/3/library/keyword.html">標準ライブラリ<code>keyword</code>&nbsp;ー Python キーワードのテスト</a></p>



<script src="https://gist.github.com/arika-python/3dd5c89d6c74f6f22ed12c4682e771ce.js"></script>



<h3 class="wp-block-heading">識別子として使用不可</h3>



<p>予約語は変数名・関数名・クラス名などの名前として使えないので注意してください。</p>



<script src="https://gist.github.com/arika-python/6de38e1b6b2a82cabac6c9bdf6ea652c.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>予約語は識別子として使おうとするとエラーになるため誤って上書きすることはありませんが、概要は押さえておきましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-reserved-word/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】raw文字列の使い方（エスケープシーケンスを無効化）</title>
		<link>https://arika-blog.com/python-r-string/</link>
					<comments>https://arika-blog.com/python-r-string/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Sat, 20 Jan 2024 13:38:39 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3024</guid>

					<description><![CDATA[Pythonにはエスケープシーケンスを処理をしないraw文字列があります。 本記事では、raw文字列の使い方と注意点について解説をします。 Python 基礎文法の教科書を執筆しました！ エスケープシーケンスとは エスケ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonにはエスケープシーケンスを処理をしないraw文字列があります。 本記事では、raw文字列の使い方と注意点について解説をします。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">エスケープシーケンスとは</h2>



<p>エスケープシーケンスとは、\(バックスラッシュ)と特定の文字を組み合わせることで、特殊な機能を持たせる記述方法になります。</p>



<script src="https://gist.github.com/arika-python/46893a2cbe683dae5fa64d49fd834530.js"></script>



<p>Pythonで認識されるエスケープシーケンスは以下の通りです。</p>



<figure class="wp-block-table aligncenter"><table><thead><tr><th>エスケープシーケンス</th><th>意味</th></tr></thead><tbody><tr><td>\&lt;newline&gt;</td><td>バックスラッシュと改行文字が無視されます</td></tr><tr><td>\\</td><td>バックスラッシュ (\)</td></tr><tr><td>\<code>'</code></td><td>一重引用符 (<code>'</code>)</td></tr><tr><td>\<code>"</code></td><td>二重引用符 (<code>"</code>)</td></tr><tr><td>\<code>a</code></td><td>ASCII 端末ベル (BEL)</td></tr><tr><td>\<code>b</code></td><td>ASCII バックスペース (BS)</td></tr><tr><td>\<code>f</code></td><td>ASCII フォームフィード (FF)</td></tr><tr><td>\<code>n</code></td><td>ASCII 行送り (LF)</td></tr><tr><td>\<code>r</code></td><td>ASCII 復帰 (CR)</td></tr><tr><td>\<code>t</code></td><td>ASCII 水平タブ (TAB)</td></tr><tr><td>\<code>v</code></td><td>ASCII 垂直タブ (VT)</td></tr><tr><td>\<code><em>ooo</em></code></td><td>8 進数値&nbsp;<em>ooo</em>&nbsp;を持つ文字</td></tr><tr><td>\<code>x<em>hh</em></code></td><td>16 進数値&nbsp;<em>hh</em>&nbsp;を持つ文字</td></tr></tbody></table><figcaption class="wp-element-caption">引用：<a href="https://docs.python.org/ja/3/reference/lexical_analysis.html#escape-sequences">https://docs.python.org/ja/3/reference/lexical_analysis.html#escape-sequences</a></figcaption></figure>



<h2 class="wp-block-heading">raw文字列の使い方</h2>



<p>文字列の先頭に<strong>ｒ</strong>または<strong>Ｒ</strong>をつけることでエスケープシーケンスを無効化することができます。</p>



<script src="https://gist.github.com/arika-python/6b109abb0b1373db87d032474e0c9d76.js"></script>



<h3 class="wp-block-heading">ファイルパスで使うと便利</h3>



<p>raw文字列を使うと便利なのがファイルパスを指定するときです。<br>ファイルパスにエスケープシーケンスが含まれている場合に使用します。</p>



<script src="https://gist.github.com/arika-python/79991a6cb9ba4de1b42cc38899961f60.js"></script>



<p>ちなみに\\でも可能です。</p>



<script src="https://gist.github.com/arika-python/84ee98cef5dee1cec88322138298ee98.js"></script>



<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-11 sbs-flat sbp-l sbis-sn cf block-box"><div class="speech-person"><figure class="speech-icon"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/2025/11/icon-1-1-1.png" alt="" class="speech-icon-image"/></figure><div class="speech-name"></div></div><div class="speech-balloon">
<p>raw文字列はファイルパスをそのまま使えるので便利ですね。</p>
</div></div>



<h4 class="wp-block-heading">\で終わるとエラーになる</h4>



<p>raw文字列はファイルパスをそのまま使えるので便利ですが、末尾が奇数個のバックスラッシュで終わるとエラーになるので注意してください。</p>



<script src="https://gist.github.com/arika-python/70aa9bd6b8e98b7ff349bed46173c472.js"></script>



<div class="wp-block-cocoon-blocks-icon-box common-icon-box block-box information-box">
<p>EOL(End Of Line): 行末を表すコード</p>
</div>



<p>終わりの対になっていないバックスラッシュが、閉じ引用文字をエスケープしてしまいます。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://docs.python.org/ja/3/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash" title="デザインと歴史 FAQ" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://docs.python.org/3.14/ja/_images/social_previews/summary_faq_design_f0141f01.png" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">デザインと歴史 FAQ</div><div class="blogcard-snippet external-blogcard-snippet">目次: デザインと歴史 FAQ- Python はなぜ文のグループ化にインデントを使うのですか？, なぜ単純な算術演算が奇妙な結果になるのですか？, なぜ浮動小数点数の計算はこんなに不正確なんですか？, なぜ Python の文字列はイミュータブルなのですか？, なぜメソッドの定義や呼び出しにおいて &#039;self&#039; を明</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://docs.python.org/3/faq/design.html" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">docs.python.org</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">まとめ</h2>



<p>raw文字列は特にファイルパスで使うと便利です。注意点をきちんと理解して、上手く使いこなしていきましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-r-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】関数アノテーションの使い方</title>
		<link>https://arika-blog.com/python-function-annotations/</link>
					<comments>https://arika-blog.com/python-function-annotations/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Fri, 05 Jan 2024 07:18:24 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=3001</guid>

					<description><![CDATA[Pythonは関数アノテーションという機能を使って、関数の引数や返り値にアノテーションを記載できます。これを使うことによって、使用方法をより明確化できます。本記事では関数アノテーションの書き方および注意点について解説しま [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonは関数アノテーションという機能を使って、関数の引数や返り値にアノテーションを記載できます。これを使うことによって、使用方法をより明確化できます。本記事では関数アノテーションの書き方および注意点について解説します。</p>



<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-11 sbs-flat sbp-l sbis-sn cf block-box"><div class="speech-person"><figure class="speech-icon"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/2025/11/icon-1-1-1.png" alt="" class="speech-icon-image"/></figure><div class="speech-name"></div></div><div class="speech-balloon">
<p>アノテーションは「注釈」という意味です。</p>
</div></div>



<p>関数の基本を確認したい方はこちらの記事をご活用ください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939/viewer/ed6a52" title="Pythonの関数定義をマスターしよう！｜【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">Pythonの関数定義をマスターしよう！｜【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet"></div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939/viewer/ed6a52" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">関数アノテーションの書き方</h2>



<p>関数アノテーションの書き方について解説します。以下の関数を使用します。</p>



<script src="https://gist.github.com/arika-python/df6901e1608908e85ed93cb504421a2e.js"></script>



<p>この関数に対して関数アノテーションを記載します。</p>



<script src="https://gist.github.com/arika-python/c4c55651ceedece65a36f8e549b59e99.js"></script>



<p><strong>引数アノテーション</strong>は引数名の後にコロンを続け、その後にアノテーションの値として評価される式を置きます。</p>



<p><strong>返り値アノテーション</strong>は、引数リストとdef文の終わりを表すコロンの間に置かれた -&gt; によって定義され、その後に式が続きます。戻り値が無い場合は<strong>None</strong>と書きます。</p>



<p><span class="marker-under-blue">今回は関数アノテーションに型ヒントを記載していますが、型ヒントを書くことは必須ではなく、それ以外の情報をアノテーションとして書くことも認められています。</span></p>



<p>また、引数にデフォルト値を設定したい場合は引数アノテーションの後に続けます。</p>



<script src="https://gist.github.com/arika-python/6e813d7e47effa5760d68af3dbc110e4.js"></script>



<p>関数アノテーションおよび型ヒントの詳細はPEP484に記載があります。PEPとは<strong>Python Enhancement Proposals</strong>（Python機能強化の提案）の略で、Pythonコミュニティに情報を提供したり、新機能を説明したりする設計文書です。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://peps.python.org/pep-0484/" title="PEP 484 – Type Hints | peps.python.org" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/9274df3cc110da1ab8e804360cf1839e.png" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">PEP 484 – Type Hints | peps.python.org</div><div class="blogcard-snippet external-blogcard-snippet">PEP 3107 introduced syntax for function annotations, but the semantics were deliberately left undefined. There has now been enough 3rd party usage for static ty</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://peps.python.org/pep-0484/" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">peps.python.org</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">使用する際の注意点</h2>



<p>使用する際の注意点などを解説します。</p>



<h3 class="wp-block-heading">アノテーションで指定した型以外の引数を渡してもエラーにならない</h3>



<p>関数アノテーションは注釈に過ぎないため、アノテーションで指定した型以外の引数を渡してもエラーになりません。</p>



<script src="https://gist.github.com/arika-python/24dd5f371e8435c9ea327c55ab64275b.js"></script>



<h3 class="wp-block-heading">__annotations__の属性にディクショナリとして格納される</h3>



<p>関数アノテーションは以下のように__annotations__属性にディクショナリとして格納されます。</p>



<script src="https://gist.github.com/arika-python/f0639bd494cadb761c63f6ef71edfbc6.js"></script>



<h2 class="wp-block-heading">ジェネリックな関数</h2>



<p>PythonはTypeVarという機能があり、<strong>呼び出し時に型が決まる</strong>汎用的(ジェネリック)な関数を作成することができます。</p>



<script src="https://gist.github.com/arika-python/a79aa47872690584847322e0ef18f56a.js"></script>



<p>つまり、<span class="marker-under-blue">引数x,yの型がTであるとき、返り値の型がTであるということです。</span></p>



<h3 class="wp-block-heading">python3.12の変更点</h3>



<p>python3.12より、TypeVarなしでジェネリックな関数を記述できるようになりました。</p>



<script src="https://gist.github.com/arika-python/6dffe70fff75fdffd40f226786887729.js"></script>



<h3 class="wp-block-heading">ジェネリックについてもう少し（主題から逸れます）</h3>



<p>python3.12で変更があったのは関数だけではなく、クラスにも変更があります。主題とは逸れますがあわせてご紹介します。</p>



<p>まず、クラスの継承は以下のようにできますが、</p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>class ClassName(BaseClassName):</p>
</div></div>



<p>python3.11以前のバージョンでは、Generic[T]を基底クラスにすることでジェネリックなクラスを定義することができました。</p>



<script src="https://gist.github.com/arika-python/8c5af991c9287de97db9386869f4f2b4.js"></script>



<p>python3.12では<strong>クラス名[型変数]</strong>でジェネリックなクラスを定義できるようになり、書き方がシンプルになりました。</p>



<script src="https://gist.github.com/arika-python/55bfb28a954421805f5bc48715de7302.js"></script>



<p>その他の変更点を知りたい方はこちらをご確認ください。</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="What&#039;s New In Python 3.12（Python3.12の新機能）" width="1256" height="707" src="https://www.youtube.com/embed/ZRUCXYbPeDo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<h2 class="wp-block-heading">まとめ</h2>



<p>関数アノテーションはあくまで注釈ですが、関数の使い方をより分かりやすくすることができます。Pythonコードの可読性向上に活用しましょう。</p>



<p>また、PythonEDに問題が掲載されているので、理解度を深めたい方は是非挑戦してみてください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://www.pythonic-exam.com/archives/6657" title="問題解説）PEP 8が推奨する関数アノテーションの使い方について、間違っているものを選択肢の中から選びなさい。 – Python試験・資格、データ分析試験・資格を運営する一般社団法人Pythonエンジニア育成推進協会のページです。" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/2310324872ad346578f946d100f7b293.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">問題解説）PEP 8が推奨する関数アノテーションの使い方について、間違っているものを選択肢の中から選びなさい。 – Python試験・資格、データ分析試験・資格を運営する一般社団法人Pythonエンジニア育成推進協会のページです。</div><div class="blogcard-snippet external-blogcard-snippet">当コラムでは、PythonZen &amp; PEP 8 検定試験（こちらでオンライン受験できます）で出題されている問題の解説を行なっています。当コラムシリーズを読んで自信がついたら、ぜひ試験に挑戦してみてくださいね。</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://www.pythonic-exam.com/archives/6657" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">www.pythonic-exam.com</div></div></div></div></a>
</div>



<p><strong>関連記事</strong><br><a href="https://arika-blog.com/python-args-kwargs/">【Pythonの可変長引数】*args、**kwargsの違いと使い方を徹底解説！</a></p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-function-annotations/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】フォーマット済み文字列リテラル(f-string)の使い方</title>
		<link>https://arika-blog.com/python-f-string/</link>
					<comments>https://arika-blog.com/python-f-string/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Thu, 14 Dec 2023 22:02:28 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=2961</guid>

					<description><![CDATA[本記事では、Python3.6以降に追加されたフォーマット済み文字列リテラル(短くしてf-stringとも呼びます)の基本的な形式、便利な機能などを紹介します。Python 2.7や3.5など、以前のバージョンでは、st [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>本記事では、Python3.6以降に追加されたフォーマット済み文字列リテラル(短くしてf-stringとも呼びます)の基本的な形式、便利な機能などを紹介します。Python 2.7や3.5など、以前のバージョンでは、str<code>.format()</code>を使う必要があります。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">f-stringとは</h2>



<p>文字列の頭に<strong>f</strong>か<strong>F</strong>を付け、式を<strong>{}</strong>の間に書くことで、変数を参照することができます。<br>ここでいう式とは、値を１つ返すものになります。</p>



<script src="https://gist.github.com/arika-python/3842a5adf285e39221d592781de87792.js"></script>



<div class="wp-block-cocoon-blocks-balloon-ex-box-1 speech-wrap sb-id-11 sbs-flat sbp-l sbis-sn cf block-box"><div class="speech-person"><figure class="speech-icon"><img decoding="async" src="https://arika-blog.com/wp-content/uploads/2025/11/icon-1-1-1.png" alt="" class="speech-icon-image"/></figure><div class="speech-name"></div></div><div class="speech-balloon">
<p>str.format()よりスッキリ書けるというメリットがあります。</p>
</div></div>



<p><strong>str.format()で書いた場合</strong></p>



<script src="https://gist.github.com/arika-python/8f7d7f0bae4530e48435bbb7b1f72c8f.js"></script>



<h2 class="wp-block-heading">便利な機能を紹介</h2>



<p>f-stringには、式展開や文字幅の指定など、便利な機能があるので一部を紹介します。<br>詳しくは公式ドキュメントをご確認ください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://docs.python.org/ja/3/reference/lexical_analysis.html#f-strings" title="2. 字句解析" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://docs.python.org/3.14/ja/_images/social_previews/summary_reference_lexical_analysis_d1ef210f.png" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">2. 字句解析</div><div class="blogcard-snippet external-blogcard-snippet">A Python program is read by a parser. Input to the parser is a stream of tokens, generated by the lexical analyzer(also known as the tokenizer). This chapter de</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://docs.python.org/3/reference/lexical_analysis.html" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">docs.python.org</div></div></div></div></a>
</div>



<h3 class="wp-block-heading">式展開</h3>



<p>中括弧内に変数だけでなく式も指定できます。</p>



<script src="https://gist.github.com/arika-python/e669feff85a50ed8a83f6c9e8a6e7200.js"></script>



<h3 class="wp-block-heading">小数の丸め</h3>



<p>fが小数、.2が小数2桁を表します。</p>



<script src="https://gist.github.com/arika-python/3ec2ababeb1fb7540a8a583c93cbb7ae.js"></script>



<h3 class="wp-block-heading">文字幅の指定</h3>



<p>nで最小の文字幅を指定することができます。dは10進数を表しています。</p>



<script src="https://gist.github.com/arika-python/42399210aa2cbb6b7b6ef7028b87ddfe.js"></script>



<p>文字幅がnを超える場合、切り詰めるようなことはしません。</p>



<script src="https://gist.github.com/arika-python/2c0d668336a0342ade729d933e4566a8.js"></script>



<h3 class="wp-block-heading">!s!r!a</h3>



<p>str() 、repr()、ascii()を適用することができます。<br>&#8216;!s&#8217; が str() 、 &#8216;!r&#8217; が repr()、&#8217;!a&#8217; が ascii() を表しています。</p>



<ul class="wp-block-list">
<li>str()：人間に読める表現を返す</li>



<li>repr()：インタープリタに読める表現を返す</li>



<li>ascii()：非ASCII文字をUnicodeエスケープする</li>
</ul>



<script src="https://gist.github.com/arika-python/6ba68741e35b0eddd5767d5bb0b061bc.js"></script>



<p>フォーマット前に適用されるので注意してください。</p>



<script src="https://gist.github.com/arika-python/66de8d137bd640a2134a6ce0a852d402.js"></script>



<h2 class="wp-block-heading">python3.12の変更点</h2>



<p>python3.12が2023年10月2日にリリースされました。<br>これにより、f-stringの制限がいくつか解除されています。</p>



<p>Python3.12の変更点を知りたい方はこちら</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe loading="lazy" title="What&#039;s New In Python 3.12（Python3.12の新機能）" width="1256" height="707" src="https://www.youtube.com/embed/ZRUCXYbPeDo?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div></figure>



<h3 class="wp-block-heading">引用符の再利用が可能に</h3>



<p>f-stringの囲みに使ったクォーテーション記号を<code>{}</code>内でも使えるようになりました。<br>python3.11以前のバージョンではSyntaxErrorになります。</p>



<script src="https://gist.github.com/arika-python/202b06ed60485f70a6a2a19571927c1b.js"></script>



<p>joinメソッドに関して詳しく知りたい方はこちら</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://docs.python.org/ja/3/library/stdtypes.html#str.join" title="組み込み型" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://docs.python.org/3.14/ja/_images/social_previews/summary_library_stdtypes_8113631d.png" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">組み込み型</div><div class="blogcard-snippet external-blogcard-snippet">以下のセクションでは、インタプリタに組み込まれている標準型について記述します。 主要な組み込み型は、数値、シーケンス、マッピング、クラス、インスタンス、および例外です。 コレクションクラスには、ミュータブルなものがあります。コレクションのメンバをインプレースに足し、引き、または並べ替えて、特定の要素を返さないメソッドは</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://docs.python.org/3/library/stdtypes.html" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">docs.python.org</div></div></div></div></a>
</div>



<p>また、これによって任意の数のf-stringをネストできるようになりました。</p>



<script src="https://gist.github.com/arika-python/ee5f419e5883d2cde3999d45f699cb56.js"></script>



<h3 class="wp-block-heading">改行と\が使用可能に</h3>



<p>python3.12では改行と\が使えるようになりました。\が使えることにより、エスケープシーケンスを含めることができます。</p>



<script src="https://gist.github.com/arika-python/49f2652be4ebd83fcff35eac887216bf.js"></script>



<script src="https://gist.github.com/arika-python/d27edfa1c5326d285778cd07b77d2e62.js"></script>



<h2 class="wp-block-heading">まとめ</h2>



<p>f-stringは書き方がシンプルでオプションが豊富にある高機能な文字列フォーマットです。Pythonコードの可読性向上に活用しましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-f-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>【Python】アンパックを使って要素を取り出す（リスト・タプル・辞書）</title>
		<link>https://arika-blog.com/python-unpack/</link>
					<comments>https://arika-blog.com/python-unpack/#respond</comments>
		
		<dc:creator><![CDATA[Pythonアカデミア]]></dc:creator>
		<pubDate>Tue, 05 Dec 2023 21:22:11 +0000</pubDate>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[文法]]></category>
		<guid isPermaLink="false">https://arika-blog.com/?p=2968</guid>

					<description><![CDATA[Pythonにはアンパック(unpack)と呼ばれる機能があります。 アンパックを使うことで要素を1つずつ取り出して変数に代入することができます。本記事では、リスト、タプル、辞書のアンパックについて解説をします。 Pyt [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Pythonにはアンパック(unpack)と呼ばれる機能があります。 アンパックを使うことで要素を1つずつ取り出して変数に代入することができます。本記事では、リスト、タプル、辞書のアンパックについて解説をします。</p>



<p class="has-text-align-center"><strong>Python 基礎文法の教科書を執筆しました！</strong></p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939" title="【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet">本書は、これからPythonを学ぶ方や初学者の方でも無理なく勉強を進められるように、図解や画像を豊富に使って説明をしています。 内容はPythonチュートリアル（公式のドキュメント）に準拠しているため、理解必須の部分をこの1冊ですべて網羅することができます。 ・プログラミング</div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">アンパックの基本的な使い方</h2>



<p>アンパックの基本構造は以下のようになります。</p>



<div class="wp-block-cocoon-blocks-tab-caption-box-1 tab-caption-box block-box has-background has-border-color has-watery-blue-background-color has-light-blue-border-color"><div class="tab-caption-box-label block-box-label box-label"><span class="tab-caption-box-label-text block-box-label-text box-label-text">構文</span></div><div class="tab-caption-box-content block-box-content box-content">
<p>変数1, 変数2, …, 変数N = 要素1, 要素2, …, 要素N</p>
</div></div>



<p>要素にリストやタプルを指定します。</p>



<h3 class="wp-block-heading">リストのアンパック</h3>



<p>変数をカンマで区切って書く（左辺）と、それぞれの変数にリストの要素（右辺）が代入されます。</p>



<script src="https://gist.github.com/arika-python/49c0a08e34beb8bbd9c13bcb8442e0d3.js"></script>



<p>冗長な記述を避けていることが分かります。</p>



<script src="https://gist.github.com/arika-python/98fc4275419d4bea3bc601c386044eba.js"></script>



<h3 class="wp-block-heading">タプルのアンパック</h3>



<p>タプルも同様です。</p>



<script src="https://gist.github.com/arika-python/26cf7fba1825fb77a5ad8b4394089152.js"></script>



<h3 class="wp-block-heading">辞書のアンパック</h3>



<p>my_dictをアンパックすると、keyの値が代入されます。</p>



<script src="https://gist.github.com/arika-python/40a1b23058e357842de53a278b68a7df.js"></script>



<p>valueの値をアンパックしたい場合はmy_dict.values()とします。</p>



<script src="https://gist.github.com/arika-python/d76429f7c18040415fffadcb5516465f.js"></script>



<p>keyとvalueの値をアンパックしたい場合はmy_dict.items()とします。</p>



<script src="https://gist.github.com/arika-python/060c812f4fce9fa0f5ec650bab87752f.js"></script>



<h2 class="wp-block-heading">変数と要素数が合っている必要がある</h2>



<p><strong>左辺の変数と右辺の要素数は一致している必要があります。</strong><br>一致しない場合はValueErrorが発生します。</p>



<script src="https://gist.github.com/arika-python/a6d449884eb37f75d8bfd73c4aefc185.js"></script>



<h3 class="wp-block-heading">アスタリスクを使って要素をまとめて代入する</h3>



<p>アスタリスクを使えば複数の要素をまとめて代入することができます。</p>



<script src="https://gist.github.com/arika-python/d47b42ea622897a5d6000a6ecf04eb14.js"></script>



<h2 class="wp-block-heading">関数の引数にアンパックした値を渡す</h2>



<p>関数の引数にリスト、タプル、辞書を渡すことができます。</p>



<p><span class="marker-under-blue">*でリストやタプルをアンパックして渡します。<br>**で辞書をアンパックをアンパックして渡します。</span></p>



<script src="https://gist.github.com/arika-python/90e4f7d36de6632282cb7c699a20293d.js"></script>



<p>関数の基本を確認したい方はこちらの記事をご活用ください。</p>



<div class="wp-block-cocoon-blocks-blogcard blogcard-type bct-none">
<a rel="noopener" href="https://zenn.dev/python_academia/books/6df147d8b82939/viewer/ed6a52" title="Pythonの関数定義をマスターしよう！｜【図解】Python 基礎文法の教科書" class="blogcard-wrap external-blogcard-wrap a-wrap cf" target="_blank"><div class="blogcard external-blogcard eb-left cf"><div class="blogcard-label external-blogcard-label"><span class="fa"></span></div><figure class="blogcard-thumbnail external-blogcard-thumbnail"><img loading="lazy" decoding="async" src="https://arika-blog.com/wp-content/uploads/cocoon-resources/blog-card-cache/207d1bc4f416570dfed7731b6853821e.jpg" alt="" class="blogcard-thumb-image external-blogcard-thumb-image" width="160" height="90" /></figure><div class="blogcard-content external-blogcard-content"><div class="blogcard-title external-blogcard-title">Pythonの関数定義をマスターしよう！｜【図解】Python 基礎文法の教科書</div><div class="blogcard-snippet external-blogcard-snippet"></div></div><div class="blogcard-footer external-blogcard-footer cf"><div class="blogcard-site external-blogcard-site"><div class="blogcard-favicon external-blogcard-favicon"><img loading="lazy" decoding="async" src="https://www.google.com/s2/favicons?domain=https://zenn.dev/python_academia/books/6df147d8b82939/viewer/ed6a52" alt="" class="blogcard-favicon-image external-blogcard-favicon-image" width="16" height="16" /></div><div class="blogcard-domain external-blogcard-domain">zenn.dev</div></div></div></div></a>
</div>



<h2 class="wp-block-heading">まとめ</h2>



<p>アンパックは複数の変数扱う場合、コードがシンプルになるメリットがあります。上手く使いこなしていきましょう。</p>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<p class="has-text-align-center"><strong>Pythonには</strong><br><strong>実力を証明できる資格があります</strong></p>



<p>PythonにはPython3エンジニア認定基礎試験という試験があります。</p>



<p>試験範囲がPythonチュートリアル（公式ドキュメント）となっているため、Pythonの基礎を全て押さえることができます。</p>



<ul class="wp-block-list">
<li>独学で勉強していて、どれくらい理解できているのか調べたい</li>



<li>今の仕事も続けつつ、キャリアの幅を広げたい</li>



<li>新しい技術としてPythonを習得したい</li>
</ul>



<p>そんな方は是非詳細をご確認ください。</p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"徹底攻略 Python3エンジニア認定基礎試験 公式問題集","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51N-pG7BCRL._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0BX343K9Y","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":0},{"id":1,"u_tx":"楽天市場で見る","u_bc":"#f76956","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/%E5%BE%B9%E5%BA%95%E6%94%BB%E7%95%A5%20Python3%E3%82%A8%E3%83%B3%E3%82%B8%E3%83%8B%E3%82%A2%E8%AA%8D%E5%AE%9A%E5%9F%BA%E7%A4%8E%E8%A9%A6%E9%A8%93%20%E5%85%AC%E5%BC%8F%E5%95%8F%E9%A1%8C%E9%9B%86\/","a_id":3715568,"p_id":54,"pl_id":27059,"pc_id":54,"s_n":"rakuten","u_so":1}],"eid":"RXR7G","s":"l"});</script><div id="msmaflink-RXR7G">リンク</div><!-- MoshimoAffiliateEasyLink END -->



<p><a href="https://arika-blog.com/python-basic-commentary/">【テキストと動画で徹底解説】Python3エンジニア認定基礎試験をまとめました</a></p>



<p><strong>おすすめ記事</strong><br><a href="https://arika-blog.com/python-threestep/">【入門者向け】効率よくPythonを習得する3Step</a><br><a href="https://arika-blog.com/python-work-book/">【難易度爆下げ】Python3エンジニア認定基礎試験 公式問題集レビュー</a><br><a href="https://arika-blog.com/python-basic-commentary-study-method/">【Python3エンジニア認定基礎試験】合格体験記からみんなの勉強方法を探ってみた</a></p>



<!-- START MoshimoAffiliateEasyLink --><script type="text/javascript">(function(b,c,f,g,a,d,e){b.MoshimoAffiliateObject=a;b[a]=b[a]||function(){arguments.currentScript=c.currentScript||c.scripts[c.scripts.length-2];(b[a].q=b[a].q||[]).push(arguments)};c.getElementById(a)||(d=c.createElement(f),d.src=g,d.id=a,e=c.getElementsByTagName("body")[0],e.appendChild(d))})(window,document,"script","//dn.msmstatic.com/site/cardlink/bundle.js?20220329","msmaflink");msmaflink({"n":"VTuberサプーが教える！　Python　初心者のコード／プロのコード","b":"","t":"","d":"https:\/\/m.media-amazon.com","c_p":"","p":["\/images\/I\/51Z0NykiT6L._SL500_.jpg"],"u":{"u":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","t":"amazon","r_v":""},"v":"2.1","b_l":[{"id":3,"u_tx":"Amazonで見る","u_bc":"#f79256","u_url":"https:\/\/www.amazon.co.jp\/dp\/B0D8KNXRK9","a_id":3719461,"p_id":170,"pl_id":27060,"pc_id":185,"s_n":"amazon","u_so":1},{"u_bc":"#f76956","u_tx":"楽天市場で見る","u_url":"https:\/\/search.rakuten.co.jp\/search\/mall\/VTuber%E3%82%B5%E3%83%97%E3%83%BC%E3%81%8C%E6%95%99%E3%81%88%E3%82%8B%EF%BC%81%E3%80%80Python%E3%80%80%E5%88%9D%E5%BF%83%E8%80%85%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89%EF%BC%8F%E3%83%97%E3%83%AD%E3%81%AE%E3%82%B3%E3%83%BC%E3%83%89\/","s_n":"rakuten","u_so":2,"a_id":3715568,"p_id":54,"pc_id":54,"pl_id":27059,"id":6}],"eid":"UpuFc","s":"s"});</script><div id="msmaflink-UpuFc">リンク</div><!-- MoshimoAffiliateEasyLink END -->
]]></content:encoded>
					
					<wfw:commentRss>https://arika-blog.com/python-unpack/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
