Python Forum
Newb question about %02d %04d
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newb question about %02d %04d
#21
As mention it gives more flexibility to have a function with parameters,than a limited print statement.
So what did we do print character at one line with between space in python 2?
# Python 2
>>> s = 'hello'
>>> for c in s:
...     print c
...     
h
e
l
l
o
>>> for c in s:
...     print c,   
...     
h e l l o
Ohhh adding , magically print it at one line with space,that's short and readable Snooty

If look at help on print() function Python 3,we see that there more choices.
>>> help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.
So Python 3 more flexibility and readable than magically ,.
# Python 3
>>> s = 'hello'
>>> for c in s:
...     print(c, end=' ')
... 
h e l l o 
>>> for c in s:
...     print(c, end='\t')
... 
h	e	l	l	o	
>>> for c in s:
...     print(c, end='**')
... 
h**e**l**l**o**
Reply


Messages In This Thread
Newb question about %02d %04d - by bennylava - Oct-16-2018, 03:39 AM
RE: Newb question about %02d %04d - by buran - Oct-16-2018, 06:06 AM
RE: Newb question about %02d %04d - by bennylava - Nov-06-2018, 03:46 PM
RE: Newb question about %02d %04d - by nilamo - Nov-06-2018, 03:59 PM
RE: Newb question about %02d %04d - by bennylava - Dec-11-2018, 11:01 AM
RE: Newb question about %02d %04d - by buran - Dec-11-2018, 11:14 AM
RE: Newb question about %02d %04d - by bennylava - Dec-11-2018, 12:30 PM
RE: Newb question about %02d %04d - by buran - Dec-11-2018, 01:03 PM
RE: Newb question about %02d %04d - by Gribouillis - Dec-11-2018, 01:41 PM
RE: Newb question about %02d %04d - by bennylava - Dec-15-2018, 03:25 PM
RE: Newb question about %02d %04d - by ichabod801 - Dec-15-2018, 03:45 PM
RE: Newb question about %02d %04d - by Gribouillis - Dec-15-2018, 03:47 PM
RE: Newb question about %02d %04d - by bennylava - Dec-27-2018, 07:29 PM
RE: Newb question about %02d %04d - by nilamo - Dec-27-2018, 07:45 PM
RE: Newb question about %02d %04d - by snippsat - Dec-27-2018, 09:47 PM
RE: Newb question about %02d %04d - by bennylava - Dec-30-2018, 11:06 PM
RE: Newb question about %02d %04d - by Larz60+ - Dec-31-2018, 01:28 AM
RE: Newb question about %02d %04d - by bennylava - Jan-06-2019, 01:35 PM
RE: Newb question about %02d %04d - by nilamo - Jan-07-2019, 03:50 PM
RE: Newb question about %02d %04d - by buran - Jan-06-2019, 02:10 PM
RE: Newb question about %02d %04d - by Gribouillis - Jan-06-2019, 02:14 PM
RE: Newb question about %02d %04d - by snippsat - Jan-06-2019, 02:53 PM
RE: Newb question about %02d %04d - by Gribouillis - Jan-06-2019, 02:55 PM
RE: Newb question about %02d %04d - by bennylava - Feb-12-2019, 07:26 AM
RE: Newb question about %02d %04d - by buran - Feb-12-2019, 07:53 AM
RE: Newb question about %02d %04d - by bennylava - Feb-12-2019, 11:29 AM
RE: Newb question about %02d %04d - by nilamo - Feb-12-2019, 05:00 PM
RE: Newb question about %02d %04d - by bennylava - Feb-14-2019, 05:58 AM
RE: Newb question about %02d %04d - by nilamo - Feb-14-2019, 07:14 PM
RE: Newb question about %02d %04d - by bennylava - Mar-05-2019, 09:44 PM
RE: Newb question about %02d %04d - by snippsat - Mar-05-2019, 11:23 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python newb need help Fictile 1 217 Apr-02-2024, 03:28 AM
Last Post: buran
  NameError issue with daughter's newb code MrGonk 2 1,454 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Simple newb string question Involute 2 2,217 Sep-08-2019, 12:50 AM
Last Post: Involute
  please help this newb install pygame iofhua 7 5,946 May-15-2019, 01:09 PM
Last Post: buran
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 2,429 Apr-15-2019, 06:19 AM
Last Post: perfringo
  Pthyon 3 question (newb) bennylava 11 5,874 Feb-28-2019, 06:04 PM
Last Post: buran
  newb selfie PatM 5 3,615 Feb-19-2019, 12:20 AM
Last Post: snippsat
  Complete NEWB and openpyxl project Netopia 44 17,340 Jan-18-2019, 08:15 PM
Last Post: Netopia
  Newb Question - Threading in Crons vvarrior 2 2,790 Jul-20-2018, 08:12 PM
Last Post: vvarrior
  Matt's newb question 1 MattSS102 1 2,708 Aug-28-2017, 03:27 AM
Last Post: BerlingSwe

Forum Jump:

User Panel Messages

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