Python Ellipsis (...) data type: Exercises with Solutions
Python ellipsis (...) Data Type [ 9 exercises with solution ]
[An editor is available at the bottom of the page to write and execute the scripts. Go to the editor]
Python's ellipsis (...) is a special built-in constant that is often used as a placeholder. It doesn't have a lot of operations associated with it, but you can use it in many ways to represent incomplete or undefined code. Ellipsis is the sole instance of the types.EllipsisType type.
1. Write a Python function that takes an arbitrary number of arguments using *args and prints each argument. Use ... to represent unspecified arguments.
Click me to see the sample solution
2. Write a Python function that takes a function as an argument and calls it with any number of arguments.
Click me to see the sample solution
3. Write a Python function that takes a multidimensional array and slices the first two elements from the third dimension.
Click me to see the sample solution
4. Write a Python program that creates a list containing numbers from 1 to 10, but leaves a gap at even positions using ellipsis.
Click me to see the sample solution
5. Write a Python program that checks if a variable is equal to ... and prints a message if it matches.
Click me to see the sample solution
6. Write a Python program that uses 'Ellipsis' to create a multidimensional array with unspecified dimensions.
Click me to see the sample solution
7. Write a Python program to create a generator expression that generates a sequence of numbers with ellipsis representing skipped values.
Click me to see the sample solution
8. Write a Python program that uses Ellipsis to extend a sequence with another sequence.
Click me to see the sample solution
9. Write a Python program that creates a custom class with an 'init' method. Use 'ellipsis' to indicate that some attributes may be added dynamically.
Click me to see the sample solution
Python Code Editor:
More to Come !
Do not submit any solution of the above exercises at here, if you want to contribute go to the appropriate exercise page.
Test your Python skills with w3resource's quiz
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics