Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I am the Python newbie.

I would like to make the code well commented.

For example, in C I can naturally write a single-line comment for every term of an expression:

int hello_world_length =

   5 + // length of "Hello"

   1 + // space between words

   5;  // length of "World"

How can I write the same statement in Python?

The code I have tried:

hello_world_length =

5 + # length of "Hello"

1 + # space between words

5   # length of "World"

hello_world_length =

   5 + # length of "Hello"

   1 + # space between words

   5   # length of "World"

hello_world_length =        \

5 + # length of "Hello"     \

1 + # space between words   \

5   # length of "World"

Neither of the above works.

I have read the Python tutorial but didn't find the solution.

1 Answer

0 votes
by (36.8k points)

Just wrap the right-hand side in parens. 4-space indentation would be common:

hello_world_length = (

    5 + # length of "Hello"

    1 + # space between words

    5   # length of "World"

)

print(hello_world_length)

11

 If you want to know more about the Data Science then do check out the following Data Science which will help you in understanding Data Science from scratch

Browse Categories

...