In Python2, print
was a keyword which introduced a statement:
print "Hi"
In Python3, print
is a function which may be invoked:
print ("Hi")
In both versions, %
is an operator which requires a string on the left-hand side and a value or a tuple of values or a mapping object (like dict
) on the right-hand side.
So, your line ought to look like this:
print("a=%d,b=%d" % (f(x,n),g(x,n)))
Also, the recommendation for Python3 and newer is to use {}
-style formatting instead of %
-style formatting:
print('a={:d}, b={:d}'.format(f(x,n),g(x,n)))
Python 3.6 introduces yet another string-formatting paradigm: f-strings.
print(f'a={f(x,n):d}, b={g(x,n):d}')
Related Posts:
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Best way to convert string to bytes in Python 3?
- Best way to convert string to bytes in Python 3?
- TypeError: not all arguments converted during string formatting python
- Convert bytes to a string
- How can I concatenate str and int objects?
- How do I format a string using a dictionary in python-3.x?
- Replacing a character from a certain index
- How to convert ‘binary string’ to normal string in Python3?
- Properly formatted multiplication table
- How to compare individual characters in two strings in Python 3
- Python cant convert ‘list’ object to str error [closed]
- Using strip() to clean up a string
- Python – difference between two strings
- How do I lowercase a string in Python?
- How to open a file using the open with statement
- How do I get a substring of a string in Python?
- How to read a file line-by-line into a list?
- strip(char) on a string
- Relative imports – ModuleNotFoundError: No module named x
- Print string to text file
- PermissionError: [Errno 13] Permission denied
- What is setup.py?
- How to remove EOFError: EOF when reading a line?
- TypeError: cannot unpack non-iterable NoneType object
- Is there a ‘foreach’ function in Python 3?
- Python inline if statement
- How to read a text file into a string variable and strip newlines?
- How to copy a dictionary and only edit the copy
- Could not find a version that satisfies the requirement tensorflow
- TypeError: ‘float’ object not iterable
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Importing class from another file [duplicate]
- Split string with multiple delimiters in Python [duplicate]
- csv.Error: iterator should return strings, not bytes
- pandas: merge (join) two data frames on multiple columns
- How to check whether a str(variable) is empty or not?
- Are dictionaries ordered in Python 3.6+?
- TypeError: method() takes 1 positional argument but 2 were given
- TypeError: write() argument must be str, not bytes (Python 3 vs Python 2 )
- How can I get a list shape without using numpy?
- What does the ‘b’ character do in front of a string literal?
- Why am I getting this syntax error: keyword can’t be an expression
- Remove all special characters, punctuation and spaces from string
- ctypes – Beginner
- How can I flush the output of the print function?
- Convert hex to binary
- ‘pip3’ is not recognized as an internal or external command, operable program or batch file
- TypeError: ‘encoding’ is an invalid keyword argument for this function
- Generate random sentences in python
- What is the Python 3 equivalent of “python -m SimpleHTTPServer”
- What does -> mean in Python function definitions?
- How do you use subprocess.check_output() in Python?
- How do I remove a substring from the end of a string?
- How do I append one string to another in Python?
- List attributes of an object [duplicate]
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Convert bytes to int?
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- Count the number of occurrences of a character in a string
- How to troubleshoot an “AttributeError: __exit__” in multiproccesing in Python?
- Type error Unhashable type:set
- Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings
- Python map object is not subscriptable
- .pyw files in python program
- ImportError: No module named ‘google’
- Get a random sample with replacement
- Django Rest Framework — no module named rest_framework
- NameError: global name ‘unicode’ is not defined – in Python 3
- Conda command is not recognized on Windows 10
- Create nice column output in python
- TypeError: int() argument must be a string, a bytes-like object or a number, not ‘list’
- Python TypeError: non-empty format string passed to object.__format__
- AttributeError: ‘Series’ object has no attribute ‘reshape’
- TypeError: decoding str is not supported
- ImportError: No module named ‘django.core.urlresolvers’
- How to do a Sigma in python 3
- Python 3: Multiply a vector by a matrix without NumPy
- How to fix “Can’t find a default Python” error
- TypeError: ‘newline’ is an invalid keyword argument for this function
- environment variables PYSPARK_PYTHON and PYSPARK_DRIVER_PYTHON
- How does str(list) work?
- Python: urllib.error.HTTPError: HTTP Error 404: Not Found
- What is the difference between a string and a byte string?
- “This constructor takes no arguments” error in __init__
- How to strip a specific word from a string?
- ValueError: cannot switch from manual field specification to automatic field numbering
- Printing subscript in python
- How to embed image or picture in jupyter notebook, either from a local machine or from a web resource?
- How can I count time in Python 3?
- What is the correct format to write float value to file in Python
- “E: Unable to locate package python3-pip”
- How to print a specific row of a pandas DataFrame?
- Python code to remove HTML tags from a string
- Accessing dict_keys element by index in Python3
- KeyError: ‘plotly_domain’
- TypeError: ‘zip’ object is not subscriptable