Python Forum
Trouble with Loops in lab assignment
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with Loops in lab assignment
#7
1) end=''
What happens if you run the print() function?
There is nothing inside the parenthesis, so you tell python to print nothing
but actually something happens on the screen.
Yeah the cursor is going one line down because you print a "Carriage return/New line" character
and this is due to the default parameter end='\n'.
Just run help(print).
So overriding this default by explicitly calling the print function with end=''
you suppress the "going to the next line" and the cursor stays behind your last output.

2) print('Name:{} Street:{} Town:{}'.format(name, street, town))
The .format() is used to conveniently insert the value of variables into a string.
You could see it as a type of concatenation.
You could code it as print('Name:', name, 'Street:', street, 'Town:', town)
Since Python 3.6 there are so-called f-strings which is an even more convenient type of
string formatting.
It would look like print(f'Name:{name} Street:{street} Town:{town}')
where in all examples name, street and town are variables.

I hope that helps you understand it.
Reply


Messages In This Thread
RE: Trouble with Loops in lab assignment - by ThomasL - Jul-28-2019, 06:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trouble with a turtle movement assignment. JosephSondgeroth 1 1,471 Jan-27-2022, 11:56 PM
Last Post: JosephSondgeroth
  Lab Assignment with Array's & Loops jonstryder 14 6,245 Aug-08-2019, 07:38 PM
Last Post: jonstryder
  Trouble with "Weather Program" Assignment sarah_mb_sues 5 9,116 Aug-10-2018, 02:29 AM
Last Post: ichabod801
  I'm having trouble with my assignment for creating a math quiz thewrongnarwhal 7 8,157 Nov-14-2016, 08:06 AM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

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