Indentation in Python Last Updated : 03 Dec, 2024 Comments Improve Suggest changes Like Article Like Report In Python, indentation is used to define blocks of code. It tells the Python interpreter that a group of statements belongs to a specific block. All statements with the same level of indentation are considered part of the same block. Indentation is achieved using whitespace (spaces or tabs) at the beginning of each line.For Example: Python if 10 > 5: print("This is true!") print("I am tab indentation") print("I have no indentation") OutputThis is true! I am tab indentation I have no indentation The first two print statements are indented by 4 spaces, so they belong to the if block.The third print statement is not indented, so it is outside the if block. If we Skip Indentation, Python will throw error. Python if 10>5: print("GeeksforGeeks") Error Indentation in Conditional StatementsThe lines print(‘GeeksforGeeks…’) and print(‘retype the URL.’) are two separate code blocks. The two blocks of code in our example if-statement are both indented four spaces. The final print(‘All set!’) is not indented, so it does not belong to the else block. Python a = 20 if a >= 18: print('GeeksforGeeks...') else: print('retype the URL.') print('All set !') OutputGeeksforGeeks... All set ! Indentation in LoopsTo indicate a block of code in Python, we must indent each line of the block by the same whitespace. The two lines of code in the while loop are both indented four spaces. It is required for indicating what block of code a statement belongs to. Python j = 1 while(j<= 5): print(j) j = j + 1 Output1 2 3 4 5 Comment More infoAdvertise with us Next Article Indentation in Python N nikhilaggarwal3 Follow Improve Article Tags : Python python-basics Practice Tags : python Similar Reads Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien 3 min read Python | Pandas Index.insert() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas Index.insert() function make new Index inserting new item at location. This fun 2 min read Print lists in Python Printing a list in Python is a common task when we need to visualize the items in the list. There are several methods to achieve this and each is suitable for different situations. In this article we explore these methods.The simplest way of printing a list is directly with the print() function:Pyth 3 min read Statement, Indentation and Comment in Python Here, we will discuss Statements in Python, Indentation in Python, and Comments in Python. We will also discuss different rules and examples for Python Statement, Python Indentation, Python Comment, and the Difference Between 'Docstrings' and 'Multi-line Comments. What is Statement in Python A Pytho 7 min read Iterate over a list in Python Python provides several ways to iterate over list. The simplest and the most common way to iterate over a list is to use a for loop. This method allows us to access each element in the list directly.Example: Print all elements in the list one by one using for loop.Pythona = [1, 3, 5, 7, 9] # On each 3 min read Python in Keyword The in keyword in Python is a powerful operator used for membership testing and iteration. It helps determine whether an element exists within a given sequence, such as a list, tuple, string, set or dictionary.Example:Pythons = "Geeks for geeks" if "for" in s: print("found") else: print("not found") 3 min read Python List index() - Find Index of Item index() method in Python is a helpful tool when you want to find the position of a specific item in a list. It works by searching through the list from the beginning and returning the index (position) of the first occurrence of the element you're looking for. Example:Pythona = ["cat", "dog", "tiger" 3 min read Python Keywords and Identifiers Every language contains words and a set of rules that would make a sentence meaningful. Similarly, in Python programming language, there are a set of predefined words, called Keywords which along with Identifiers will form meaningful sentences when used together. Python keywords cannot be used as th 10 min read Internal working of list in Python Introduction to Python lists : Python lists are internally represented as arrays. The idea used is similar to implementation of vectors in C++ or ArrayList in Java. The costly operations are inserting and deleting items near the beginning (as everything has to be moved). Insert at the end also becom 3 min read Python Built in Functions Python is the most popular programming language created by Guido van Rossum in 1991. It is used for system scripting, software development, and web development (server-side). Web applications can be developed on a server using Python. Workflows can be made with Python and other technologies. Databas 6 min read Like