Python Forum

Full Version: Two types of single quotes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In the following program, which I did not write myself, I am puzzled by something.
The code is:

import feather
import pandas as pd
import numpy as np


a = np.random.randn(1000000)
df = pd.DataFrame({'Field_{0}'.format(i): a for i in range(10)})
df.head()


get_ipython().run_line_magic('time', "feather.write_dataframe(df, 'feather.file')")
I am curious about the single quotes around 'Field_{0}'. It only runs when they are the same. The single quote in right hand side of the keyboard next to the enter key. There is another single quote in the upper left hand corner below the escape key which is not used.

How are these single quotes different in python 3.8.2?

When are they different?

In other computer languages when putting the single quotes around something, both
must be used and in a specific order.

In the little python program I have shown only the single quote next to the enter key works - it is used twice. There may be other combinations, but I am just unsure how both quotes are used in python.

So what is (are) the rule(s)?

Thanks

LZ
It is called backtick (GRAVE ACCENT char) and it had a meaning in python 2 syntax. See https://stackoverflow.com/questions/1384...-in-python

It was depreciated in python3
Quote:Removed backticks (use repr() instead).
The one on the tilde key (by escape) is an accent not a quote. See if this helps you distinguish the two.
print (ord ("'"), ord ("`"))
The single quote works the same as the double quote in python. One handy way to use both is:

print ('He yelled "BASHBEDLAM!"')