関数が何も返さない理由
Python では、関数は値を返すことが期待されています。明示的な return ステートメントが指定されていない場合、デフォルトの戻り値は None です。ただし、これは、特に関数が明示的に何も返さずに特定のアクションを実行することが期待されている場合に混乱を招く可能性があります。
次のコードを考えてみましょう。
def print_multiplication(n): i = 1 while i <p>この関数は、次の乗算表を出力します。数値は 30 です。関数内の print ステートメントは、return ステートメントを使用せずに各積を出力します。したがって、関数はデフォルトで None を返します。</p><p><strong>戻り値について</strong></p><p>print ステートメントは九九を表示することを目的としていますが、何も返しません。その結果、print_multiplication(30) も None を返します。戻り値を出力しようとすると、期待される出力の代わりに None が出力されます。</p><p><strong>関数の修正</strong></p><p>この問題を解決するには、目的の出力を指定する必要があります。戻り値。この関数は特定のデータを返さずにタスクを実行することを目的としているため、None キーワードを明示的に使用できます。</p><pre class="brush:php;toolbar:false">def print_multiplication(n): i = 1 while i <p>明示的に None を返すことで、関数が Python の規則に従って値を返すようになります。特定のデータを提供する。これで、戻り値を出力すると、None が正しく出力されます。</p>
以上がPython 関数が時々「None」を返すのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

forhandlinglaredataSetsinpython、usenumpyArrays forbetterperformance.1)numpyarraysarememory-effictientandfasterfornumericaloperations.2)nusinnnnedarytypeconversions.3)レバレッジベクトル化は、測定済みのマネージメーシェイメージーウェイズデイタイです

inpython、listsusedynamicmemoryallocation with allocation、whilenumpyArraysalocatefixedmemory.1)listsallocatemorememorythanneededededinitivative.2)numpyArrayasallocateexactmemoryforements、rededicablebutlessflexibilityを提供します。

inpython、youcanspecthedatatypeyfelemeremodelernspant.1)usenpynernrump.1)usenpynerp.dloatp.ploatm64、フォーマーpreciscontrolatatypes。

numpyisessentialfornumericalcomputinginpythonduetoitsspeed、memory efficiency、andcomprehensivematicalfunctions.1)それは、performsoperations.2)numpyArraysaremoremory-efficientthanpythonlists.3)Itofderangeofmathematicaloperty

contiguousMemoryAllocationisucial forArraysは、ForeffienceAndfastelementAccess.1)iteenablesConstantTimeAccess、O(1)、DuetodirectAddresscalculation.2)itemprovesefficiencyByAllowingMultiblementFechesperCacheLine.3)itimplifieMememm

slicingapythonlistisdoneusingtheyntaxlist [start:stop:step] .hore'showitworks:1)startisthe indexofthefirstelementtoinclude.2)spotisthe indexofthefirmenttoeexclude.3)staptistheincrementbetbetinelements

numpyallows forvariousoperationsonarrays:1)basicarithmeticlikeaddition、減算、乗算、および分割; 2)AdvancedperationssuchasmatrixMultiplication;

Arraysinpython、特にnumpyandpandas、aresentialfordataanalysis、offeringspeedandeficiency.1)numpyarraysenable numpyarraysenable handling forlaredatasents andcomplexoperationslikemoverages.2)Pandasextendsnumpy'scapabivitieswithdataframesfortruc


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

Dreamweaver Mac版
ビジュアル Web 開発ツール

メモ帳++7.3.1
使いやすく無料のコードエディター

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

ホットトピック









