Python Forum
trying to understand a string literal in a basic server program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to understand a string literal in a basic server program
#2
This is using the format language for f-strings. The first bit inside the braces is the thing you want to evaluate (and print the str() representation of), and the second bit (after the colon) is the Format specification mini-language.

In your particular case the less-than sign indicates left alignment within the field and HEADERSIZE is evaluated and interpreted as the size of the field.

>>> headersize = 10
>>> n = 45
>>> f"{n}"
'45'
>>> f"{n:{headersize}}"
'        45'
>>> f"{n:<{headersize}}"
'45        '
Reply


Messages In This Thread
RE: trying to understand a string literal in a basic server program - by bowlofred - Nov-13-2021, 11:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to understand the function string.split() Hudjefa 8 3,153 Sep-16-2024, 04:25 AM
Last Post: Pedroski55
  Basic Coding Question: Exit Program Command? RockBlok 3 2,125 Nov-19-2023, 06:31 PM
Last Post: deanhystad
  How to take the tar backup files form remote server to local server sivareddy 0 2,711 Jul-14-2021, 01:32 PM
Last Post: sivareddy
  PLEASE HELP! Basic Python Program joeroffey 5 3,703 Apr-10-2021, 02:59 PM
Last Post: jefsummers
  EOF while scanning triple-quoted string literal louis216 1 5,432 Jun-30-2020, 04:11 AM
Last Post: bowlofred
  invalid literal for int() with base 10: '' mrsenorchuck 5 13,101 Apr-29-2020, 05:48 AM
Last Post: markfilan
  Python basic program webshakeup 4 4,071 Sep-19-2019, 07:14 AM
Last Post: Maheshsharma
  Syntax Error EOL while scanning string literal intjuma 0 3,039 Jun-28-2019, 01:56 AM
Last Post: intjuma
  Heating program to translate from Basic to Python tommy2k19 12 8,858 May-21-2019, 08:16 AM
Last Post: tommy2k19
  Very Basic String Manipulation gstu 2 3,422 Mar-18-2018, 03:08 PM
Last Post: gstu

Forum Jump:

User Panel Messages

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