Menu

Executive Programs

Workshops

Projects

Blogs

Careers

Student Reviews



More

Academic Training

Informative Articles

Find Jobs

We are Hiring!


All Courses

Choose a category

Loading...

All Courses

All Courses

logo

Mechanical

Modified on

24 Nov 2022 08:07 pm

What Is Indentation In Python?

logo

Skill-Lync

Indentation refers to the spaces at the starting of a line of code. While in other programming languages the indentation in code is for readability alone, the indentation in Python has much more significance.

What do we need in Indentation in Python?

Simply, put an indentation helps the interpreter distinguish a block of code. A Python interpreter can be informed that a group of statements belongs to a specific block of code by using Python indentation. Any combination of these assertions is known as a block. The grouping of statements into a block might be thought of as serving a specific function. Braces are commonly used in programming languages like C, C++, and Java to define code blocks. Python employs indentation to draw attention to the code chunks. Python uses whitespace to indicate indentation. The same block of code contains all statements spaced to the right by the same amount. A block is simply indented further to the right if it needs to be more deeply nested.

What are Indentation Errors?

  • If any of the spaces are not given or aren't properly aligned python will display the ‘indentation error’ as shown above.

  • Also, a mismatched number of spaces with the lines inside the loop will throw the indentation error as above.

  • If the spaces have been mixed with tab and spacebar spaces while providing indentation python will throw up the error as above.

EXAMPLES:

Missing out the indentation:

  • Indentation is not given for the above code and so the block(for loop) will be left unindented and the following error will show up.

SOLUTION:

  • Proper indentation should be provided as shown below,

Mismatching in a number of spaces in the block:

  • Here the line “B.append(c)” is not having the same indentation as the line above, which throws up the indentation error as below,

SOLUTION:

  • The number of spaces should be matching with all the lines in the same block and no matter how many spaces we are using but it should be constant over the block as shown below.

Inconsistent use of tab spaces in the block:

  • Here the spaces given in the lines are inconsistent which includes the spaces using both tab spaces and space bar, which makes up the indentation error.

SOLUTION:

  • Using uniform spaces for the indentation with either using a tab space or a space bar avoids indentation errors.

 


Author

author

Navin Baskar


Author

blogdetails

Skill-Lync

Subscribe to Our Free Newsletter

img

Continue Reading

Related Blogs

Shock tube simulation

Learn how to render a shock-tube-simulation and how to work on similar projects after enrolling into anyone of Skill-Lync's CAE courses.

Mechanical

10 May 2020


Design of Frontal BIW enclosure of a car (Bonnet)

In this blog, read how to design the frontal BIW enclosure of a car (Bonnet) and learn how Skill-Lync Master's Program in Automotive Design using CATIA V5 will help you get employed as a design engineer.

Mechanical

10 May 2020


What is Tetra Meshing?

Tetrahedral is a four- nodded solid element that can be generated through the tria element by creating a volume and also through the existing volume of the geometry. These elements are used where the geometry has high thickness and complexity. The image attached below is a representation of a Tetra element. The Tetra element will have 4 triangular faces with four nodes joining them together

Mechanical

02 Aug 2022


Realizing Connectors In HyperMesh

A connector is a mechanism that specifies how an object (vertex, edge, or face) is connected to another object or the ground. By often simulating the desired behaviour without having to build the precise shape or specify contact circumstances, connectors make modeling simpler.

Mechanical

03 Aug 2022


Mesh Sizing In Ansys Workbench

One of the most crucial processes in carrying out an accurate simulation using FEA is meshing. A mesh is composed of elements that have nodes—coordinate positions in space that might change depending on the element type—that symbolise the geometry's shape.

Mechanical

04 Aug 2022



Author

blogdetails

Skill-Lync

Subscribe to Our Free Newsletter

img

Continue Reading

Related Blogs

Shock tube simulation

Learn how to render a shock-tube-simulation and how to work on similar projects after enrolling into anyone of Skill-Lync's CAE courses.

Mechanical

10 May 2020


Design of Frontal BIW enclosure of a car (Bonnet)

In this blog, read how to design the frontal BIW enclosure of a car (Bonnet) and learn how Skill-Lync Master's Program in Automotive Design using CATIA V5 will help you get employed as a design engineer.

Mechanical

10 May 2020


What is Tetra Meshing?

Tetrahedral is a four- nodded solid element that can be generated through the tria element by creating a volume and also through the existing volume of the geometry. These elements are used where the geometry has high thickness and complexity. The image attached below is a representation of a Tetra element. The Tetra element will have 4 triangular faces with four nodes joining them together

Mechanical

02 Aug 2022


Realizing Connectors In HyperMesh

A connector is a mechanism that specifies how an object (vertex, edge, or face) is connected to another object or the ground. By often simulating the desired behaviour without having to build the precise shape or specify contact circumstances, connectors make modeling simpler.

Mechanical

03 Aug 2022


Mesh Sizing In Ansys Workbench

One of the most crucial processes in carrying out an accurate simulation using FEA is meshing. A mesh is composed of elements that have nodes—coordinate positions in space that might change depending on the element type—that symbolise the geometry's shape.

Mechanical

04 Aug 2022


Book a Free Demo, now!

Related Courses

https://d28ljev2bhqcfz.cloudfront.net/maincourse/thumb/vehicle-dynamics-matlab_1636606203.png
Vehicle Dynamics using MATLAB
4.8
37 Hours of content
Cae Domain
Know more
https://d28ljev2bhqcfz.cloudfront.net/maincourse/thumb/introduction-control-electric-vehicle_1612329773.png
4.9
16 Hours of content
Electrical Domain
https://d28ljev2bhqcfz.cloudfront.net/mainproject/thumb/meshing-and-connections-deployment-of-rear-suspension-of-a-car-73676_1616585003.jpgRecently launched
0 Hours of content
Cae Domain
Showing 1 of 6 courses