Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two types of single quotes
#1
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
Reply
#2
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).
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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!"')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need help on how to include single quotes on data of variable string hani_hms 5 2,012 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Remove single and double quotes from a csv file in 3 to 4 column shantanu97 0 6,974 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Quotes vs. no quotes around numbers Mark17 6 3,142 Aug-06-2020, 04:13 AM
Last Post: t4keheart
  Can I delete single quotes in string matrix display sylas 2 3,488 Jul-22-2017, 10:18 AM
Last Post: sylas
  Double Quotes will not go away, must be missing something smiths87 3 5,076 May-03-2017, 11:45 PM
Last Post: smiths87
  Help with strange syntax - two single quotes after variable mvrk 1 3,352 Jan-25-2017, 10:56 AM
Last Post: buran

Forum Jump:

User Panel Messages

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