format sorting

Asked 2 years ago, Updated 2 years ago, 79 views

I'm curious about the role of a,b when we say {a:bd}.

When you say {a:b.cf} I'm curious about the role of a.

Thank you for your answer Have a great day!

format

2022-09-20 10:21

2 Answers

https://docs.python.org/ko/3/library/stdtypes.html#str.format

str.format(*args, **kwargs)

Performs a string format operation. The string to which this method is invoked can contain a substitution field separated by literal text or brackets {}. Each replacement field can have a numeric index of the position factor or the name of the keyword factor. Returns a copy of the string that replaces each substitution field with the value of the string for that factor.

>>> "{1} {3} {0} {2}".format("A", "B", "C", "D")
'B D A C'


2022-09-20 10:21

https://docs.python.org/3/library/string.html#formatspec

It's all in the previously delivered link.

I think the first image is wrong For right-hand alignment, the command is >.

I will omit the meaning of a for each example because Daewon summarized it.

# Setting the number of spaces
a = 123
b = f'{a:14}' # == f'{a:>14}'
print([b])
>> ['           123']

# Left Alignment
a = 123
b = f'{a:<14}'
print([b])
>> ['123           ']

# Centrally
a = 123
b = f'{a:^14}'
print([b])
>> ['     123      ']


2022-09-20 10:21

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.