• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

what does {w} do in Python

 
Ranch Hand
Posts: 40
1
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could somebody please help? On lines 12 - 16 what purpose is {w} used for? Is it a TAB?

 
MyExamCloud Software Support
Posts: 734
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is f-strings's space between two strings.

name = "Tom"
age = 30
w = 10

print(f"{'Name:':{w}}{name}") # w = 10 between 'Name:' and 'Tom'
print(f"{'Age:':{w}}{age}")

Print:

Name:     Tom
Age:      30
 
Martin Gerard
Ranch Hand
Posts: 40
1
Netbeans IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jhonson Fernando
reply
    Bookmark Topic Watch Topic
  • New Topic