Python Program: Checking and handling ellipsis in variables

Python ellipsis (...) Data Type: Exercise-5 with Solution

Write a Python program that checks if a variable is equal to ... and prints a message if it matches.

Sample Solution:


# Define a list with ellipsis as a placeholder
nums = [1, 2, 3, 4, 5, 6, ...]  
for item in nums:
    if item is ...:
    print(f"Reading item: {item}")


Reading item: 1
Reading item: 2
Reading item: 3
Reading item: 4
Reading item: 5
Reading item: 6

The exercise above defines a list 'nums' with 'ellipsis' as a placeholder for unspecified items. In the loop, we check if the current item is 'ellipsis (...)', and if it is, we print "Skipping...". Otherwise, we process the item and print a message indicating that we are processing it. By using 'ellipsis' as a marker for skipped or unspecified items, we can iterate over an unknown number of items.


Flowchart: Python Program: Checking and handling ellipsis in variables.

Previous: Python Program: Creating lists with gaps using ellipsis.
Next: Python: Creating multidimensional arrays with unspecified dimensions.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.

Follow us on Facebook and Twitter for latest update.

Python: Tips of the Day

Summing a sequence of numbers (calculating the sum of zero to ten with skips):

>>> l = range(0,10,2)
>>> sum(l)


We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook