+ 1
Name = "{{{}}}" Name. Format("something") Why the answer is {something} ?
8 Antworten
+ 3
'{{' is like an escape for '{'. When you use '{' or '}' in a string, Python thinks that it has to be replaced with a format argument. Therefore to use '{' or '}' in a string, you need to use '{{' or '}}' respectively. In you example, the first 2 '{' are considered to be 1 '{' and the last 2 '}}'nare considered to be 1 '}' and the '{}' in the centre is replaced by the argument.
+ 2
Gautam Yadav it is because you are not passing format arguments to it. '{{' is considered as '{' only when the string is either a f-string or .format() is called on the string. Else the string will stay as it is.
+ 1
XXX then why it's not the same as you said when I do something like this name = "{{{something}}}" ? Answer : '{{{something}}}'
+ 1
Ok XXX
0
What do you want to get as a result?
0
Bánk Kozma 'something' may be Or an error
0
Bánk Kozma but not that!
0
XXX thanks you are sweet :)