Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
string formatting
#1
Hi, i want to ask that when using string formatting:
>>> b={1:'a','1':'c'}
>>> print('%(1)s abcd' % b)
c abcd
How can we refer to the keys 1 (has value 'a') not the key '1' (has 'c' value).
Thank you very much!
Reply
#2
>> print('some {spam}'.format(**foo))
some a
>>> print(f'some {foo["eggs"]}')
some b
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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Formatting a date time string read from a csv file DosAtPython 5 1,240 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  String formatting (strptime) issues Henrio 2 838 Jan-06-2023, 06:57 PM
Last Post: deanhystad
  confused about string formatting barryjo 7 1,974 Mar-06-2022, 02:03 AM
Last Post: snippsat
  string formatting barryjo 7 2,035 Jan-02-2022, 02:08 AM
Last Post: snippsat
  Help with string formatting in classes brthurr 6 8,832 Dec-17-2021, 04:35 PM
Last Post: Jeff900
  Question on HTML formatting with set string in message Cknutson575 3 3,451 Mar-09-2021, 08:11 AM
Last Post: Cknutson575
  smtplib: string formatting not carrying over to email ClassicalSoul 1 2,641 Apr-22-2020, 09:58 PM
Last Post: bowlofred
  String formatting difficulties mmk1995 3 2,749 Aug-09-2019, 11:18 AM
Last Post: wavic
  TypeError: not all arguments converted during string formatting RedSkeleton007 1 14,957 Jul-15-2018, 08:51 PM
Last Post: ichabod801
  formatting string and returning as geojson garynobles 12 6,603 Mar-06-2018, 05:02 PM
Last Post: garynobles

Forum Jump:

User Panel Messages

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