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
#1
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?
Reply
#2
It looks you refer to old-style string formatting.
Check this link https://docs.python.org/3.7/library/stdt...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/stri...matstrings
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I think I'll only be programming in Python 2. So for me those aren't really old style.
Reply
#4
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?
Reply
#5
(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.
Reply
#6
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).
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#7
(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.
Reply
#8
(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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
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.
Reply
#10
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError issue with daughter's newb code MrGonk 2 1,406 Sep-16-2021, 01:29 PM
Last Post: BashBedlam
  Simple newb string question Involute 2 2,169 Sep-08-2019, 12:50 AM
Last Post: Involute
  please help this newb install pygame iofhua 7 5,846 May-15-2019, 01:09 PM
Last Post: buran
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 2,388 Apr-15-2019, 06:19 AM
Last Post: perfringo
  Pthyon 3 question (newb) bennylava 11 5,743 Feb-28-2019, 06:04 PM
Last Post: buran
  newb selfie PatM 5 3,544 Feb-19-2019, 12:20 AM
Last Post: snippsat
  Complete NEWB and openpyxl project Netopia 44 16,878 Jan-18-2019, 08:15 PM
Last Post: Netopia
  Newb Question - Threading in Crons vvarrior 2 2,719 Jul-20-2018, 08:12 PM
Last Post: vvarrior
  Matt's newb question 1 MattSS102 1 2,669 Aug-28-2017, 03:27 AM
Last Post: BerlingSwe
  Newb: Simple Explicit Formula Duplicitous 1 3,108 May-05-2017, 07:03 PM
Last Post: buran

Forum Jump:

User Panel Messages

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