title: How to run a single line or selected code in a Jupyter Notebook or JupyterLab cell?
body: <p>In both JupyterLab and Jupyter Notebook you can execute a cell using <code>ctrl + Enter</code>:</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>print('line 1')
  print('line 2')
  print('line 3')
  </code></pre>
  
  <p><strong>Cell and output:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/ts8CC.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ts8CC.png" alt="cell and output"></a></p>
  
  <p>But how can you run <em>only</em> <code>line 2</code>? Or even a selection of lines within a cell without running the entire cell? Sure you could just insert a cell with that single line or selection of lines, but that gets really cumbersome and messy really quick. So are there better ways of doing this?</p>