How do I format my content as a code block?
DataCamp’s editor uses Markdown to format your text so that it renders as code. However, "code" and "code blocks" render differently and, not surprisingly, it's because they are formatted differently.
If you wish to format a single variable or function name, surround your text with single back-ticks (located in the upper left on your keyboard). Your variable or function will then render like this
variable or this
If you want an entire code block, you need to surround your code with three sequential back-ticks at the top and the bottom of the block.
# This is a code block example
Just make sure you add a line break before and after your code, or your code block won't render properly.
What should be formatted as code?
As you'd expect, any code should be formatted as code! This includes code blocks, variables, and functions. There are a few grey areas. Here's how we format at DataCamp:
Column names are formatted as code.
Library names should be formatted as code when referring to code, as in the following example: "
numpyis loaded as
np, and the
tree_censusarray is available." However, library names aren't formatted as code if the context doesn't refer to code: "NumPy is a foundational Python library."
Even strings should be formatted as code if the string will be part of the learner's code if copied verbatim. For example, we'd write, "Filter the data to include only results where sex equals
F." However, this same instruction could also be formatted as "Filter the data to include only results where the sex is female." The word "female" is not formatted as code, because the word female is not an expected part of the learner's code in the correct solution.