

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print a complete tuple in Python using string formatting?
When using the old style of string formatting in python, ie, "" % (), if the thing after the percent is a tuple, python tries to break it down and pass individual items in it to the string. For example,
tup = (1,2,3) print("this is a tuple %s" % (tup))
This will give the output:
TypeError: not all arguments converted during string formatting
This is because of the reason mentioned above. If you want to pass a tuple, you need to create a wrapping tuple using the (tup, ) syntax. For example,
tup = (1,2,3) print("this is a tuple %s" % (tup, ))
This will give the output:
this is a tuple (1, 2, 3)
The (tup,) notation differentiates a single-valued tuple from an expression.
- Related Questions & Answers
- String Formatting in Python using %?
- How to print complete TimeTuple in Python?
- String Formatting in C# using %
- String Formatting in Java using %
- String Formatting Operator in Python
- How to compare Python string formatting: % with .format?
- How can I convert a Python tuple to string?
- Convert String to Tuple in Python
- Traditional C formatting in Arduino print
- How to print concatenated string in Python?
- How can we do the basic print formatting for Python numbers?
- How to print duplicate characters in a String using C#?
- Program to print path from root to all nodes in a Complete Binary Tree using C++
- How does string formatting work in PowerShell?
- Formatting a string to separate identical characters in JavaScript
Advertisements