What are collections named tuples in Python

One of the most common uses of tuples is in the print statement. Here is an example:

$ python print_tuple.py Swaroop is 22 years old. Why is Swaroop playing with this python?

The instruction can be given a string with special information, followed by a -sign and a tuple of objects that match the information in the string. This information is used to format the output in a certain way. For example, they can consist of one for strings and one for integers. The tuple must have objects that correspond to these specifications in the same order.

Notice the first application where we first use what corresponds to the variable that is the first object in the tuple, and as a second statement, what corresponds to the second object in the tuple.

Python converts each object of the tuple into a string and uses this instead of the formatting specifications. Therefore it is replaced by the value of the variable and so on.

This use of the statement makes it extremely easy to get output to the screen and avoids a lot of string manipulations that could accomplish the same thing. You can also avoid using commas, as we have done so far.

Most of the time, you can just use it and let Python take care of the rest. It even works for numbers. However, you can also provide the correct information in order to incorporate a further check for correctness into your program.

In the second statement, we use a single formatting specification followed by a character and a single object - there is no pair of brackets here. However, this only works in the case that there is only a single formatting specification in the string.