im taking a summer course for python and came across this python code:
num1 = input( ) # input will be 10
num2 = input( ) # input will be 20
num3 = num1 + num2
print (f'The sum is {num3:<50}')
what does this last piece do inside the curly brace {num3: <50}? What does that <50 mean??
Any help appreciated, thanks !
>Solution :
It means the value is left aligned within the given space of 50 chars which makes little sense if nothing is coming after:
>>> num3 = 3.14
>>> f'The sum is {num3:<50} hello')
'The sum is 3.14 hello'
From the docs on string format syntax on "<":
Forces the field to be left-aligned within the available space (this is the default for most objects).