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

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

Pages: 1 2 3 4


Newb question about %02d %04d - bennylava - Oct-16-2018

Hi all, new here. I'm just starting to learn Python, and it will be my first language. I've been at it for about 3 weeks. I've made it to a place in my studies, where I'd just like to hear another human tell me about something. And that is, these things:


%02d and %04d and %s

I think there are others as well. Such as %d and others. I know that % can be used to get the remainder of the division between two numbers. But what is all this other stuff?


RE: Newb question about %02d %04d - buran - Oct-16-2018

It looks you refer to old-style string formatting.
Check this link https://docs.python.org/3.7/library/stdtypes.html#printf-style-string-formatting
As I said this is old style formatting and it still works, but preferred/recommended is to use str.format(), template strings or formatted string literals, a.k.a f-strings (in python 3.6+)
More information https://docs.python.org/3.7/library/string.html#formatstrings


RE: Newb question about %02d %04d - bennylava - Nov-06-2018

I think I'll only be programming in Python 2. So for me those aren't really old style.


RE: Newb question about %02d %04d - nilamo - Nov-06-2018

Here ye, here ye! The days are numbered!
https://pythonclock.org/

Is there a reason you're using something which will soon no longer even have bug fixes?


RE: Newb question about %02d %04d - bennylava - Dec-11-2018

(Nov-06-2018, 03:59 PM)nilamo Wrote: Here ye, here ye! The days are numbered!
https://pythonclock.org/

Is there a reason you're using something which will soon no longer even have bug fixes?

Yeah a few reasons, CodeAcademy has the best interface imo, and they only offer python 2. I'm also a newb and to me, python 2 seems to have less steps for some things. I took a look at 3 and its a bit different, and I noticed the way some things are done... well they just have a bit more to type. I may not be able to articulate it at this stage but I'm sure you guys would know what I'm talking about. So I figured I'd just learn 2 first, and since 3 is so similar it wouldn't take much for me to learn 3 as well. Since my CodeAcademy only offers 2 for now, and they're free and have interactive lessons.

May not matter though, I'm going to be starting programming class at the local college in a month, and my guess is that they teach 3 there.


RE: Newb question about %02d %04d - buran - Dec-11-2018

You realise that first you say python3 is "a bit different" (more typing, things done differently, etc.) and then you say you figured 3 is "so similar".
As to particular question, let's rephrase my answer
using % for string formatting is ancient. .format() is available in both python2 and python3 for quite some time and then f-strings is the newest addition (since 3.6).


RE: Newb question about %02d %04d - bennylava - Dec-11-2018

(Dec-11-2018, 11:14 AM)buran Wrote: You realise that first you say python3 is "a bit different" (more typing, things done differently, etc.) and then you say you figured 3 is "so similar".
As to particular question, let's rephrase my answer
using % for string formatting is ancient. .format() is available in both python2 and python3 for quite some time and then f-strings is the newest addition (since 3.6).

Yeah when I was typing it but I thought it would be apparent that at this early stage I am just trying to gain some decent understanding of what I'm doing. I'll concern myself with how many different ways 1 thing can be done at a later time when I'm not just trying to learn the basic fundamentals. I realize you are just trying to help... maybe you can explain why that is important? Does the % method simply not function in python 3?

Also I noticed the link said python 2.7 will stop being supported in a year. But what about 2.8? I have to ask.


RE: Newb question about %02d %04d - buran - Dec-11-2018

(Dec-11-2018, 12:30 PM)bennylava Wrote: Also I noticed the link said python 2.7 will stop being supported in a year. But what about 2.8? I have to ask.

No, not 2.7, but the whole 2.x branch:
Python2 or Python3

as to the other question - the new formatting options, i.e. .format() and f-strings offer more options/power/flexibility.
For comparison between %-style and .format() see https://pyformat.info. Note how many times it says This operation is not available with old-style formatting.


RE: Newb question about %02d %04d - Gribouillis - Dec-11-2018

Quote:But what about 2.8? I have to ask.
There never will be a python 2.8. This is PEP 404 which dates back to 2011.


RE: Newb question about %02d %04d - bennylava - Dec-15-2018

Another thing I wanted to ask about. Maybe its nothing. But I've read a few different places, people saying "Well python 3 isn't really python." and then they don't elaborate much. At first I just wrote it off as one of those things people say but I've seen it enough now to make me curious as to why they'd say that. It doesn't seem all that different to me, from python 2. Certainly not enough to say that.