Python Forum
Quotes vs. no quotes around numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quotes vs. no quotes around numbers
#1
This code works:
if '2011' in baby_names:
    print('Found 2011')
    
if 1 in baby_names[2012]:
     print('Found Rank 1 in 2012')
else:
    print('Rank 1 missing from 2012')
    
if 5 in baby_names[2013]:
    print('Found Rank 5')
 
Why is 2011 in quotes (Line 1) whereas 1 and 5 (Lines 4 and 9, respectively) are not? This trips me up frequently. Thanks!
Reply


Messages In This Thread
Quotes vs. no quotes around numbers - by Mark17 - Aug-05-2020, 01:40 PM
RE: Quotes vs. no quotes around numbers - by buran - Aug-05-2020, 01:47 PM
RE: Quotes vs. no quotes around numbers - by Mark17 - Aug-05-2020, 02:38 PM
RE: Quotes vs. no quotes around numbers - by buran - Aug-05-2020, 02:42 PM

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,329 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  Reading list items without brackets and quotes jesse68 6 4,864 Jan-14-2022, 07:07 PM
Last Post: jesse68
  Why does absence of print command outputs quotes in function? Mark17 2 1,486 Jan-04-2022, 07:08 PM
Last Post: ndc85430
  Remove single and double quotes from a csv file in 3 to 4 column shantanu97 0 7,153 Mar-31-2021, 10:52 AM
Last Post: shantanu97
  Two types of single quotes Led_Zeppelin 2 2,013 Mar-15-2021, 07:55 PM
Last Post: BashBedlam
  Remove double quotes from the list ? PythonDev 22 9,310 Nov-05-2020, 04:53 PM
Last Post: snippsat
  Correct syntax for a variable inside a quotes: MP4Box command JonnyDriller 2 2,864 Feb-02-2020, 01:22 AM
Last Post: JonnyDriller
  Cannot Remove the Double Quotes on a Certain Word (String) Python BeautifulSoup soothsayerpg 5 7,282 Oct-27-2019, 09:53 AM
Last Post: newbieAuggie2019
  Quotes and variables in print statement Mark17 4 3,168 Sep-13-2019, 04:07 PM
Last Post: Mark17
  removing quotes from a list and keep type list evilcode1 3 2,411 Aug-03-2019, 11:07 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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