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 9,537 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 9,510 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Remove double quotes from the list ? PythonDev 22 15,990 Nov-05-2020, 04:53 PM
Last Post: snippsat
  Quotes vs. no quotes around numbers Mark17 6 6,434 Aug-06-2020, 04:13 AM
Last Post: t4keheart
  Quotes and variables in print statement Mark17 4 5,396 Sep-13-2019, 04:07 PM
Last Post: Mark17
  fastest way to record values between quotes paul18fr 5 5,027 Apr-15-2019, 01:51 PM
Last Post: snippsat
  Can I delete single quotes in string matrix display sylas 2 4,757 Jul-22-2017, 10:18 AM
Last Post: sylas
  Double Quotes will not go away, must be missing something smiths87 3 7,570 May-03-2017, 11:45 PM
Last Post: smiths87
  Help with strange syntax - two single quotes after variable mvrk 1 4,326 Jan-25-2017, 10:56 AM
Last Post: buran
  <SOLVED>os.system needs a string in quotes Fred Barclay 12 23,873 Oct-06-2016, 07:06 PM
Last Post: Ofnuts

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.