Python Forum
printing strings with format
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
printing strings with format
#1
Case 1: If I execute the following:

print('{} {}'.format('one', 'two'))
the output in the IDLE shell will be

one two

Case 2: But I execute the following in IDLE:
>>> x = '{} {}'.format('one', 'two')
>>> x
the output will be

'one two'

Why is the output without strings in the first case and with quotes in the second? I understand that there is an implicit print following the primary prompt, i.e. >>>
So why is the output different.

Case 3: Also, in the following:
After defining x, if the

>>>print(x)
The output is:

one two

Is it simply that the implicit Python print after >>> not format outputted strings without quotes?
Reply


Messages In This Thread
printing strings with format - by leodavinci1990 - Aug-21-2020, 01:17 AM
RE: printing strings with format - by micseydel - Aug-21-2020, 02:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to understand strings and lists of strings Konstantin23 2 1,910 Aug-06-2023, 11:42 AM
Last Post: deanhystad
  Splitting strings in list of strings jesse68 3 2,721 Mar-02-2022, 05:15 PM
Last Post: DeaD_EyE
  Finding multiple strings between the two same strings Slither 1 3,361 Jun-05-2019, 09:02 PM
Last Post: Yoriz
  For loops, strings and printing words with even characters Drone4four 8 8,551 Oct-05-2018, 09:23 AM
Last Post: volcano63
  format strings syntax error VikramSuh 2 4,445 Sep-06-2018, 11:41 AM
Last Post: VikramSuh
  lists, strings, and byte strings Skaperen 2 5,126 Mar-02-2018, 02:12 AM
Last Post: Skaperen
  printing strings on same line.. anna 3 3,983 Jan-18-2018, 10:43 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