Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mysterious Extra New-Line
#1
Hey,

So I am doing exercises out of a Python book I am reading and for some reason this code is printing two new-lines between "- turkey" and "- bacon" and I was hoping someone could explain to me why this is:

def order_sandwich(*items):
    for item in items:
        print("- " + item)

order_sandwich('turkey')

print("\n")

order_sandwich('bacon', 'lettuce', 'tomato')
When I write it like this, I only get one new-line, which is what I was expecting from the first snippet:

def order_sandwich(*items):
    for item in items:
        print("- " + item)

order_sandwich('turkey\n')

order_sandwich('bacon', 'lettuce', 'tomato')
What am I missing? Huh
Reply


Messages In This Thread
Mysterious Extra New-Line - by trevorkavanaugh - Feb-27-2019, 06:56 AM
RE: Mysterious Extra New-Line - by gontajones - Feb-27-2019, 10:43 AM
RE: Mysterious Extra New-Line - by trevorkavanaugh - Feb-27-2019, 07:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysterious Indentation Problem Dakodak 11 4,818 Jun-24-2019, 06:23 AM
Last Post: Dakodak
  An Extra 'None' leoahum 5 4,072 Oct-18-2018, 08:20 PM
Last Post: volcano63
  python export to csv writes extra line between rows jahjahcity 4 10,705 Jul-25-2018, 01:36 AM
Last Post: jahjahcity
  csv module writing extra line ChipsSlave 3 2,786 Jun-05-2018, 12:25 PM
Last Post: buran
  Mysterious syntax errors... help? friendlymegalomaniac 3 3,067 Apr-26-2018, 09:22 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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