Python Forum
What is this formatting called?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is this formatting called?
#1
Here's some brief code from an online Python exercise:

exam_st_date = (11,12,2014)
print( "The examination will start from : %i / %i / %i"%exam_st_date)
What is this type of formatting called? I want to learn more about it as I couldn't come up with any other way to extract and/or convert the specified date tuple into mm/dd/yyyy format (i.e. using datetime methods). Thanks!
Reply
#2
Never mind. I googled those exact same two lines of code and found a discussion on another board that answers my question. Sorry for the trouble.
Reply
#3
It's called string formatting and the oldest way with eg %i %s,should not be used anymore.
In Python 3.6 we got f-string,that is what you should use now.
from datetime import datetime, date

exam_st_date = datetime(2014,11,12)
print(f'The examination will start from: {exam_st_date:%m/%d/%Y}')
print(f'The examination will start from: {date.today():%m/%d/%Y}')
Output:
The examination will start from: 11/12/2014 The examination will start from: 12/14/2020
Mark17 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Multiple variable inputs when only one is called for ChrisDall 2 449 Oct-20-2023, 07:43 PM
Last Post: deanhystad
  Couldn't install a go-game called dlgo Nomamesse 14 2,977 Jan-05-2023, 06:38 PM
Last Post: Nomamesse
  how can a function find the name by which it is called? Skaperen 18 3,322 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  function with 'self' input parameter errors out with and without 'self' called dford 12 2,995 Jan-15-2022, 06:07 PM
Last Post: deanhystad
  Class Instances called in the wrong order IanIous 4 2,777 Mar-06-2020, 02:16 PM
Last Post: IanIous
  How do you add the results together each time a function is called? Exsul 10 4,998 Aug-09-2019, 09:18 PM
Last Post: ichabod801
  Called Functions Not Working WhatAmIDoing09 3 2,506 Jul-12-2019, 07:02 PM
Last Post: ichabod801
  Getting error when called through instance method aankrose 2 2,537 Mar-02-2019, 07:19 PM
Last Post: aankrose
  How is space of variables/functions/objects... called? j.crater 4 5,013 Dec-19-2016, 12:24 PM
Last Post: j.crater

Forum Jump:

User Panel Messages

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