Tips And Tricks / Stack Overflow

5 Ways to Embed Code in Stack Overflow

The five easy ways to embed code in Stack Overflow

Bipin P.
Analytics Vidhya
Published in
3 min readMar 8, 2020

--

Stack Overflow is a discussion forum for professional and enthusiast programmers where a wide range of topics on computer programming are featured. It’s a privately-held question and answer website owned by Stack Exchange Inc.

It is often a bit confusing(especially for beginners) on the ways to embed code snippets when trying to post a question in Stack Overflow. In this article, we are dealing with the five easy ways to embed code in Stack Overflow.

The First Way

The first and the most techie way(at least to me) is to press Ctrl + K (in Windows) and Cmd + K (in Mac). Start by copying code to the Body.

Select all the code(as shown in the image above), press Ctrl + K(in Windows) and Cmd + K (in Mac). Then immediately the preview of the text changes and will appear in a background color of #EFF0F1 as shown below(indicating that the code snippet has been recognized as code):

The Second Way

This method involves selecting the code and pressing the curly brackets icon above the text area(as shown in the image below highlighted with an orange circle).

The Third Way

The third way is to create code fences around your code by creating a pair of three backticks(one above the code and one after the code) as shown below:

```
output = np.array([pareto.pdf(x, scale = xm, b = a) for a in alphas])
plt.plot(x, output.T)
plt.show()
```

Backtick is typically placed on the left side of the numeral 1 key or next to the alphabet Z key(in Mac).

The Fourth Way

The fourth way creates inline code spans by placing code snippets within a pair of backticks.

`print("Hello World")
print('Hello')`

The Fifth Way

The fifth and final way is to skip a line and indent the code 8 spaces(even 4 spaces also work) as shown in the image below:

You can click on ‘Code’ in the formatting tips’ menu to get quick tips.

That’s it, folks!!! Happy Coding

--

--

Bipin P.
Analytics Vidhya

Data Science Enthusiast striving to secure greater goals