Python Forum
Newb question about %02d %04d - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Newb question about %02d %04d (/thread-13450.html)

Pages: 1 2 3 4


RE: Newb question about %02d %04d - snippsat - Jan-06-2019

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**



RE: Newb question about %02d %04d - Gribouillis - Jan-06-2019

Not to mention
>>> print(*'hello', sep='**')
h**e**l**l**o



RE: Newb question about %02d %04d - nilamo - Jan-07-2019

(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).


RE: Newb question about %02d %04d - bennylava - Feb-12-2019

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?


RE: Newb question about %02d %04d - buran - Feb-12-2019

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


RE: Newb question about %02d %04d - bennylava - Feb-12-2019

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.


RE: Newb question about %02d %04d - nilamo - Feb-12-2019

Once you know python 2, the difference in syntax between that and python 3 are so minimal, you can switch over in minutes.


RE: Newb question about %02d %04d - bennylava - Feb-14-2019

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.


RE: Newb question about %02d %04d - nilamo - Feb-14-2019

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.


RE: Newb question about %02d %04d - bennylava - Mar-05-2019

Well I got a couple of more questions for you guys.

1. Does the code below seem convoluted to yall? Particularly the part where they had me do str(row_count). What is the purpose of that? If you were making a spreadsheet, why wouldn't you just set the number of rows to be 1,000? They lose me on some of this stuff.

2. My next question is in regards to commas. Its little things like this that hang me up. How do you know when you can use a comma, and when you can't? Again if you look below, you can see the use of commas. But I've tried to use them in some situations, and things just didn't work out. This sounds like a dumb question to me but: Wouldn't python just disregard the commas if you couldn't use them? Can someone go into when you can use commas, and when you can't?

# Define create_spreadsheet():
def create_spreadsheet(title, row_count = 1000):
  print("Creating a spreadsheet called " + title + " with " + str(row_count) + " rows")

# Call create_spreadsheet() below with the required arguments:
create_spreadsheet("Downloads")
create_spreadsheet(title = "Applications", row_count = 10)