


Python が「IndentationError: unindent is not match any external indentation level」をスローするのはなぜですか?
スペースまたはタブを使用して一貫してインデントする
Python で「IndentationError: unindent doesn't match any external indentation level」エラーが発生した場合、一見正しいインデントであっても、多くの場合、インデントは不一致を示しています。 indentation.
具体的には、Python ではインデントにスペースまたはタブを一貫して使用する必要があります。これらの文字を混在させると混乱が生じ、上記のエラーが発生する可能性があります。
例:
次のコードを考えてみましょう:
import sys def Factorial(n): # Return factorial result = 1 for i in range (1,n): result = result * i print "factorial is ",result return result
このコードインデントにタブとスペースが混在しているため、エラーが発生します。これを修正するには、タブをスペースに置き換えるか、その逆を行います。
スペースの使用:
import sys def Factorial(n): # return factorial result = 1 for i in range(1, n): result = result * i print("factorial is ", result) return result print(Factorial(10))
タブの使用:
import sys def Factorial(n): result = 1 for i in range(1, n): result = result * i print("factorial is ", result) return result print(Factorial(10))
コード全体でインデントが一貫していることを確認し、スペースとタブの混在を避けてください。このエラーを防ぐため。
以上がPython が「IndentationError: unindent is not match any external indentation level」をスローするのはなぜですか?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

Pythonは解釈された言語ですが、コンパイルプロセスも含まれています。 1)Pythonコードは最初にBytecodeにコンパイルされます。 2)ByteCodeは、Python Virtual Machineによって解釈および実行されます。 3)このハイブリッドメカニズムにより、Pythonは柔軟で効率的になりますが、完全にコンパイルされた言語ほど高速ではありません。

useaforloopwhenteratingoverasequenceor foraspificnumberoftimes; useawhileloopwhentinuninguntinuntilaConditionismet.forloopsareidealforknownownownownownownoptinuptinuptinuptinuptinutionsituations whileoopsuitsituations withinterminedationations。

pythonloopscanleadtoErrorslikeinfiniteloops、ModifiningListsDuringiteration、Off-Oneerrors、Zero-dexingissues、およびNestededLoopinefficiencies.toavoidhese:1)use'i

forloopsareadvastountousforknowterations and sequences、offeringsimplicityandeadability;

pythonusesahybridmodelofcompilation andtertation:1)thepythoninterpretercompilessourcodeodeplatform-indopent bytecode.2)thepythonvirtualmachine(pvm)thenexecuteTesthisbytecode、balancingeaseoputhswithporformance。

pythonisbothintersedand compiled.1)it'scompiledtobytecode forportabalityacrossplatforms.2)bytecodeisthenは解釈され、開発を許可します。

loopsareideal whenyouwhenyouknumberofiterationsinadvance、foreleloopsarebetterforsituationsは、loopsaremoreedilaConditionismetを使用します

henthenumber ofiterationsisknown advanceの場合、dopendonacondition.1)forloopsareideal foriterating over for -for -for -saredaverseversives likelistorarrays.2)whileopsaresupasiable forsaresutable forscenarioswheretheloopcontinupcontinuspificcond


ホットAIツール

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

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

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

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

人気の記事

ホットツール

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

WebStorm Mac版
便利なJavaScript開発ツール

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

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

VSCode Windows 64 ビットのダウンロード
Microsoft によって発売された無料で強力な IDE エディター
