Python Forum
How to do line continuation in Jupyter Notebook?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to do line continuation in Jupyter Notebook?
#1
Hi all,

This:

#print('Date is {}, DTE is {}, EXP is {}, STRIKE is {}, PRICE is {}, VOL is {}, \
OI is {}, and DELTA is {}'.format(DATE, DTE, EXP, STRIKE, PRICE, VOL, OI, DELTA))


results in:

File "<ipython-input-70-20e6b91ee4d8>", line 2
OI is {}, and DELTA is {}'.format(DATE, DTE, EXP, STRIKE, PRICE, VOL, OI, DELTA))
^
SyntaxError: invalid syntax

It's one commented line with a backslash [trying] to indicate that what follows is a continuation of the same line.

What am I doing wrong with regard to the backslash?

Mark
Reply
#2
remove comment from line 1 and then indent line 2
Mark17 likes this post
Reply
#3
Unfortunately the continuation does not work for comments. You need to comment the second line also.
Mark17 likes this post
Reply
#4
(Sep-22-2021, 07:55 AM)ibreeden Wrote: Unfortunately the continuation does not work for comments. You need to comment the second line also.

Did not know that. Thanks.

For a regular line, after the backslash can I indent however I please or do I need to use four spaces?
Reply
#5
You are free to use the indentation you like on continuation lines. But good programmers do it according to PEP 8, which contains guidelines about formatting of code. Read the details in: Indentation.
In short: use at least the same indentation as the starting line or 4 spaces more. Or more spaces if it helps clarifying the coherence of the code.
Mark17 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm trying to import a dataset into a Jupyter Notebook Hisilat03 0 704 Mar-24-2025, 09:26 AM
Last Post: Hisilat03
  Jupyter Notebook cell ? flaviu2 6 4,873 Feb-10-2025, 09:39 AM
Last Post: mysqlguider
  import data (.csv) into Jupyter notebook oranstprotonme 2 1,155 Aug-14-2024, 07:08 PM
Last Post: oranstprotonme
  Troubleshooting Jupyter Notebook installation with Python using pip and a venv Drone4four 1 2,015 Jun-04-2024, 10:55 PM
Last Post: Drone4four
  My code works on Jupyter Lab/Notebook, but NOT on Visual Code Editor jst 4 4,110 Nov-15-2023, 06:56 PM
Last Post: jst
  Navigating file directories and paths inside Jupyter Notebook Mark17 5 7,813 Oct-29-2023, 12:40 PM
Last Post: Mark17
  How to programmatically stop a program in Jupyter Notebook? Mark17 11 58,968 Feb-12-2023, 01:41 PM
Last Post: jp21in
Thumbs Up Python 3 Jupyter notebook ternary plot data nicholas 0 1,809 Jan-21-2023, 05:01 PM
Last Post: nicholas
  Graphs from Jupyter notebook to word Scott 0 1,575 Nov-28-2022, 06:16 AM
Last Post: Scott
  Opening an empty Jupyter notebook in VSCODE Krischu 3 3,264 Mar-09-2022, 01:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020