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
#31
(Mar-05-2019, 09:44 PM)bennylava Wrote: Particularly the part where they had me do str(row_count). What is the purpose of that?
It convert integer to string,it's used because the string is bad build up.
We use string formatting to avoid + str() and many " in one string.
In 3.6 did we get f-string,that takes over for format().
It looks a lot better like this.
def create_spreadsheet(title, row_count=1000):
      print(f"Creating a spreadsheet called {title} with {row_count} rows")

create_spreadsheet(title = "Applications", row_count=10)
Output:
Creating a spreadsheet called Applications with 10 rows
(Mar-05-2019, 09:44 PM)bennylava Wrote: Can someone go into when you can use commas, and when you can't?
Can look at is a separator between values/elements that used is many different cases.
In function over it separate function parameter title and row_count=1000
With two values it will separate automatic into a tuple.
>>> 1, 2
(1, 2)
>>> 'hello', 'world', 99
('hello', 'world', 99)
In a list a natural way to separate elements.
>>> lst = ['hello', 'car', 999]
>>> lst
['hello', 'car', 999]
>>> lst[2]
999
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,848 May-15-2019, 01:09 PM
Last Post: buran
  Newb question: Debugging + Linting Python in Visual Studio Code Drone4four 1 2,390 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,545 Feb-19-2019, 12:20 AM
Last Post: snippsat
  Complete NEWB and openpyxl project Netopia 44 16,885 Jan-18-2019, 08:15 PM
Last Post: Netopia
  Newb Question - Threading in Crons vvarrior 2 2,721 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