Bottom Page

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?
Quote
#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
Quote
#3
I think I'll only be programming in Python 2. So for me those aren't really old style.
Quote
#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?
buran likes this post
Quote
#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.
Quote
#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).
Quote
#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.
Quote
#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.
Quote
#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.
Quote
#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.
Quote

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)