🌐
Python
docs.python.org β€Ί 3 β€Ί library β€Ί string.html
Common string operations β€” Python 3.14.7 documentation
An expression of the form '.name' ... argument specifiers can be omitted for str.format(), so '{} {}'.format(a, b) is equivalent to '{0} {1}'.format(a, b)....
🌐
Real Python
realpython.com β€Ί python-formatted-output
A Guide to Modern Python String Formatting Tools – Real Python
February 1, 2025 - When you use Python to format strings with positional arguments, you must choose between either automatic or explicit replacement field numbering.
Discussions

format strings and named arguments in Python - Stack Overflow
Named replacement fields (the {...} parts in a format string) match against keyword arguments to the .format() method, and not positional arguments. Keyword arguments are like keys in a dictionary; order doesn't matter, as they are matched against a name. If you wanted to match against positional arguments, use numbers: ... In Python ... More on stackoverflow.com
🌐 stackoverflow.com
python - Positional arguments in string formatting: str.format vs f-string - Stack Overflow
When trying out some features with the new (and awesome) python 3 literal string interpolation, I found this weird difference. For example, using the old str.format, I can format integers with a d... More on stackoverflow.com
🌐 stackoverflow.com
Why does it say missing 1 required positional argument
'part1, part2' is not two strings, it's a single string containing a comma. You mean 'part1', 'part2'. More on reddit.com
🌐 r/learnpython
5
0
July 23, 2024
__new__() takes 2 positional arguments but 6 were given
super() will follow the MRO: https://www.python.org/download/releases/2.3/mro/ And __new__() is a static method always called before __init__() is called, and so will not behave like __init__() at all: https://www.python.org/download/releases/2.2/descrintro/# new If you really want to override __new__() in a parent class, you need to handle all potential arguments: https://stackoverflow.com/questions/10788976/how-do-i-properly-inherit-from-a-superclass-that-has-a-new-method But I don't think you want to do that. You were just using__new__() because you did not know how to use __init__() from both parent classes, I believe you're saying. If you need to call __init__() from both parent classes, super() will not work by itself (due to how the MRO is defined). You need to just specify the parent class explicitly and call the method. Employee.__init__(self,EmployeeID,Gender,Salary,PerformanceRating) and JoiningDetail.__init__(self,DateOfJoining) in your case. So you can indeed specify __init__() in both parents classes. You're also not including self. when you're trying to refer to instance attributes. Here's your code, corrected: class Employee: def __init__(self,EmployeeID,Gender,Salary,PerformanceRating): self.EmployeeID = EmployeeID self.Gender = Gender self.Salary = Salary self.PerformanceRating = PerformanceRating def get_details(self): print ("\nEmployeeID :",self.EmployeeID) print ("Gender :",self.Gender) print ("Salary :",self.Salary) print ("PerformanceRating :",self.PerformanceRating,"\n") class JoiningDetail(): def __init__(self,DateOfJoining): self.DateOfJoining= DateOfJoining def getDOJ(self): print ("DateOfJoining :",self.DateOfJoining,"\n") class Information(Employee,JoiningDetail): def __init__(self,EmployeeID,Gender,Salary,PerformanceRating,DateOfJoining): Employee.__init__(self,EmployeeID,Gender,Salary,PerformanceRating) JoiningDetail.__init__(self,DateOfJoining) def readData(self): print("Incomplete") num = int(input("Enter the number of emplyees :")) for i in range(num): EmployeeID = input("Enter the EmployeeID :") Gender = str(input("Enter the Gender :")) Salary = int(input("Enter the Salary :")) PerformanceRating = int(input("Enter the PerformanceRating out of 5:")) DateOfJoining = (input("Enter the date of joining in DD/MM/YY format :")) e1= Information(EmployeeID,Gender,Salary,PerformanceRating,DateOfJoining) e1.get_details() e1.getDOJ() e1.readData() More on reddit.com
🌐 r/pythonhelp
4
2
May 25, 2022
🌐
DataCamp
campus.datacamp.com β€Ί courses β€Ί regular-expressions-in-python β€Ί formatting-strings
Positional formatting | Python
Positional formatting works in the following way. We put placeholders defined by a pair of curly braces in a text. We call the string dot format method. Then, we pass the desired value into the method. The method replaces the placeholders using the values in order of appearance.
🌐
CodeRivers
coderivers.org β€Ί blog β€Ί python-format-positional-arguments
Python Format Positional Arguments: A Comprehensive Guide - CodeRivers
February 22, 2026 - Positional arguments in Python's format() method are values that are inserted into a string based on their position. The format() method replaces placeholders in a string with the actual values passed as arguments.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί methods β€Ί string β€Ί format
Python String format()
In the template string, these keyword arguments are not retrieved as normal strings to be printed but as the actual format codes fill, align and width. The arguments replaces the corresponding named placeholders and the string 'cat' is formatted accordingly. Likewise, in the second example, 123.236 is the positional argument and, align, width and precision are passed to the template string as format codes.
🌐
Python
peps.python.org β€Ί pep-3101
PEP 3101 – Advanced String Formatting | peps.python.org
Formatter provides an extensible wrapper around the same C functions as are used by string.format(). The Formatter class takes no initialization arguments: ... β€˜format’ is the primary API method. It takes a format template, and an arbitrary set of positional and keyword arguments.
🌐
PyFormat
pyformat.info
PyFormat: Using % and .format() for great good!
With this site we try to show you ... style string formatting API with practical examples. All examples on this page work out of the box with with Python 2.7, 3.2, 3.3, 3.4, and 3.5 without requiring any additional libraries. Further details about these two formatting methods can be found in the official Python documentation: ... If you want to contribute more examples, feel free to create a pull-request on Github! ... Simple positional formatting ...
Top answer
1 of 2
142

Named replacement fields (the {...} parts in a format string) match against keyword arguments to the .format() method, and not positional arguments.

Keyword arguments are like keys in a dictionary; order doesn't matter, as they are matched against a name.

If you wanted to match against positional arguments, use numbers:

"{0} {1}".format(10, 20)

In Python 2.7 and up, you can omit the numbers; the {} replacement fields are then auto-numbered in order of appearance in the formatting string:

"{} {}".format(10, 20) 

The formatting string can match against both positional and keyword arguments, and can use arguments multiple times:

"{1} {ham} {0} {foo} {1}".format(10, 20, foo='bar', ham='spam')

Quoting from the format string specification:

The field_name itself begins with an arg_name that is either a number or a keyword. If it’s a number, it refers to a positional argument, and if it’s a keyword, it refers to a named keyword argument.

Emphasis mine.

If you are creating a large formatting string, it is often much more readable and maintainable to use named replacement fields, so you don't have to keep counting out the arguments and figure out what argument goes where into the resulting string.

You can also use the **keywords calling syntax to apply an existing dictionary to a format, making it easy to turn a CSV file into formatted output:

import csv

fields = ('category', 'code', 'price', 'description', 'link', 'picture', 'plans')
table_row = '''\
    <tr>
      <td><img src="{picture}"></td>
      <td><a href="{link}">{description}</a> ({price:.2f})</td>
   </tr>
'''

with open(filename, 'rb') as infile:
    reader = csv.DictReader(infile, fieldnames=fields, delimiter='\t')
    for row in reader:
        row['price'] = float(row['price'])  # needed to make `.2f` formatting work
        print table_row.format(**row)

Here, picture, link, description and price are all keys in the row dictionary, and it is much easier to see what happens when I apply the row to the formatting string.

2 of 2
8

Added benefits include

  • You don't have to worry about the order of the arguments. They will fall in the right place in the strings as indicated by their names in the formatter.
  • You can put the same argument in a string twice, without having to repeat the argument. E.g. "{foo} {foo}".format(foo="bar") gives 'bar bar'

Note that you can give extra arguments without causing errors as well. All this is especially useful when

  • you change the string formatter later on with less changes and thus smaller posibility for mistakes. If it does not contain new named arguments, the format function will still work without changing the arguments and put the arguments where you indicate them in the formatter.
  • you can have multiple formatter strings sharing a set of arguments. In this case you could for instance have a dictionary with the all arguments and then pick them out in the formatter as you need them.

E.g.:

>d = {"foo":"bar", "test":"case", "dead":"beef"}
>print("I need foo ({foo}) and dead ({dead})".format(**d))
>print("I need test ({test}) and foo ({foo}) and then test again ({test})".format(**d))
I need foo (bar) and dead (beef)
I need test (case) and foo (bar) and then test again (case)
Find elsewhere
🌐
Real Python
realpython.com β€Ί python-string-formatting
Python String Formatting: Available Tools and Their Features – Real Python
December 1, 2024 - Note that to fill the string templates, you use the ** operator to unpack the data from the input dictionary. ... Strings in Python have a built-in operation that you can access with the modulo operator (%). This operator lets you do positional ...
🌐
Linux Hint
linuxhint.com β€Ί python_string_formatting
Python String Formatting – Linux Hint
Next, the BMI value will calculate based on weight and height values. format() method is used in the script to print these three values using positional parameters. #!/usr/bin/env python3 # Take weight value weight = float(input("What is your weight in kg?\n")) # Take height value height = float(input("What is your height in meter?\n")) # Calculate BMI value based on height and weight BMI=round((weight/(height*height)),2) # Print the formatted output using multiple parameters print('Your height is {1} and weight is {0}\nYour BMI is:{2}'.format(weight,height,str(BMI)))
🌐
DataCamp
datacamp.com β€Ί tutorial β€Ί python-string-format
Python String format() Tutorial | DataCamp
October 23, 2020 - Adjust the strings so they are lowercase. Finally, print the variables first_pos and second_pos. # Assign the substrings to the variables first_pos = wikipedia_article[3:19].lower() second_pos = wikipedia_article[21:44].lower() When we run the above code, it produces the following result: ... Try it for yourself. To learn more about positional formatting, please see this video from our course, Regular Expressions in Python.
🌐
Blogger
pyright.blogspot.com β€Ί 2010 β€Ί 01 β€Ί python-31-string-formatting-positional.html
pyright: Python 3.1 String Formatting - Positional Arguments
This usually results in fewer positions, and, hopefully, less confusion. Quickie example: >>> class Foo: >>> def __init__(self): >>> pass >>> >>> a = Foo() >>> a.foo = 24 >>> a.bar = 33 >>> a.baz = 6 >>> # Python 2 string formatting >>> # print '%d %d %d' % (a.foo, a.bar, a.baz) >>> print('{0.foo} {0.bar} {0.baz}'.format(a)) 24 33 6 It's true that the left side is a bit more involved now with the new string formatting.
🌐
MindMajix
mindmajix.com β€Ί python β€Ί string-formatting
Python String Formatting | Methods to Use | MindMajix - 2025
March 29, 2017 - The format() function simply reads the arguments provided in the parameters and then reformats the string according to them. However, the formatting varies as per the positional or keyword arguments. The argument lists in Python begin from the 0. In the example given below, argument 0 is defined as a string β€˜User’ whereas the argument 1 is a floating number 1142.7238.
🌐
iO Flood
ioflood.com β€Ί blog β€Ί python-string-format
Python String format() Function Guide (With Examples)
December 5, 2023 - Throughout this guide, we’ve explored the ins and outs of Python string formatting. From the basic format() function, handling positional and keyword arguments, to the more advanced techniques like f-strings and the percent (%) operator, we’ve covered a wide range of methods to handle string formatting in Python.
🌐
W3Schools
w3schools.com β€Ί python β€Ί ref_string_format.asp
Python String format() Method
Remove List Duplicates Reverse ... Python Interview Q&A Python Training ... The format() method formats the specified value(s) and insert them inside the string's placeholder....
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python-string-format-method
Python String format() Method - GeeksforGeeks
March 26, 2025 - Hangup (SIGHUP) Traceback (most ... 3 out of range for positional args tuple Β· We can use escape sequences to format strings in a more readable way. Escape sequences allow us to insert special characters such as newline \n, tab \t, or quotes. In Python, {} placeholders in ...
🌐
Python
docs.python.org β€Ί 3.4 β€Ί library β€Ί string.html
6.1. string β€” Common string operations β€” Python 3.4.10 documentation
format() is the primary API method. It takes a format string and an arbitrary set of positional and keyword arguments.
🌐
Guru99
guru99.com β€Ί home β€Ί python β€Ί python string format() explain with examples
Python String format() Explain with EXAMPLES
July 10, 2026 - The first value will be replaced with the first empty curly bracket, followed by the next one. For positional arguments, the index will start from 0 and so on. The values will be available in format separated with commas, and the 0th value will ...
🌐
w3resource
w3resource.com β€Ί python β€Ί python-format.php
Python String Formatting
April 14, 2026 - The format() method is used to perform a string formatting operation. The string on which this method is called can contain literal text or replacement fields delimited by braces {}. Each replacement field contains either the numeric index of ...