Bottom Page

Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newb question about %02d %04d
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
>>> 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(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='**')
Not to mention
>>> print(*'hello', sep='**')
(Jan-06-2019, 01:35 PM)bennylava Wrote: Well I've got a question about python 3 already. Why did they switch to having a parenthesis if you want to print a string? In python to you didn't have to have parenthesis.

Because it makes sense for it to be a function, instead of a magic statement. One of the core ideas of python is that it's clean and legible, and magic statements are neither clean nor legible. It's also the only statement in the language which caused side effects. And because it was a statement, you couldn't use it everywhere (like in lambdas, or lists).
I have another question that relates to most of the discussion in this thread. Would you guys say that python 2 is very similar to python 3? Or were there some pretty significant changes? Is it more similar than it is different?
I would say it's definitely more similar than different, but there were some significant changes that made python3 even better programming language than python2
Well the reason I ask is because I think today I've... hit a wall. I'm beginning to question the wisdom of jumping ship in the middle of learning Python 2. I'm starting to think that I should just finish python 2 on code academy, and try to get a certificate. Then, work for a year somewhere (wherever I can) and really learn from on the job experience. Then, once it can be said that I understand it well, then upgrade to the better language that is Python 3.

I'm thinking my trouble stems from Code academy, to me it seems they've really dropped the ball on their Python 3 lessons. They're not nearly as good as the Python 2 lessons in my opinion. So much so that I'm considering going elsewhere to learn, and asking for a refund. It looks to me like they're attempting to take too many shortcuts with their teaching. Likely saving them time and money in the process.

So I'm kind of at a stopping point in my studies of programming, which for me really sucks. As I desire to keep moving forward. But I have to figure out the best thing to do.
Once you know python 2, the difference in syntax between that and python 3 are so minimal, you can switch over in minutes.
To read this thread you'd think it was a bad idea to learn python 2. As "They'll stop supporting it soon." That is what put me off of that idea.
If that particular method of learning is better suited for python 2, then go for it. Just, once you're done, look up what's changed in 3.x, and use 3.x for projects once you're done learning.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  newb selfie PatM 5 88 Yesterday, 12:20 AM
Last Post: snippsat
  Pthyon 3 question (newb) bennylava 7 226 Feb-14-2019, 05:54 AM
Last Post: bennylava
  Complete NEWB and openpyxl project Netopia 44 1,084 Jan-18-2019, 08:15 PM
Last Post: Netopia
  Newb Question - Threading in Crons vvarrior 2 376 Jul-20-2018, 08:12 PM
Last Post: vvarrior
  Matt's newb question 1 MattSS102 1 713 Aug-28-2017, 03:27 AM
Last Post: BerlingSwe
  Newb: Simple Explicit Formula Duplicitous 1 868 May-05-2017, 07:03 PM
Last Post: buran

Forum Jump:

Users browsing this thread: 1 Guest(s)