Python None data type exercises with solutions
This resource offers a total of 50 Python None Data Type problems for practice. It includes 10 main exercises, each accompanied by solutions, detailed explanations, and four related problems.
[An Editor is available at the bottom of the page to write and execute the scripts.]
1. Return None for Empty String
Write a Python function that takes a string as input and returns "None" if the string is empty, otherwise it returns the given string.
Click me to see the sample solution
2. Middle Character or None
Write a Python function that returns the middle character of a string or "None" if the string length is odd.
Click me to see the sample solution
3. Iterate and Print Strings
Write a Python program that iterates through a list of strings and prints each string. If a string is empty, print "Empty string" instead.
Click me to see the sample solution
4. Descending Order List Check
Write a Python function that checks if a given list is sorted in descending order. Return None if the list is empty.
Click me to see the sample solution
5. Uppercase Conversion with None Check
Write a Python program that takes a user's input and converts it to uppercase. If the input is empty, return None.
Click me to see the sample solution
6. Dictionary Key Retrieval with Default
Write a Python program that defines a dictionary and retrieves a value using a key. If the key is not found, return None.
Click me to see the sample solution
7. Recursive None Counter
Write a Python function that counts None values in a list recursively. Return 0 if the list is empty.
Click me to see the sample solution
8. Conditional Sum of Two Arguments
Write a Python function that takes two arguments and returns their sum if both aren't None, otherwise return None.
Click me to see the sample solution
9. Insert None Between Elements
Write a Python function that takes a list and returns a new list with None inserted between each element.
Click me to see the sample solution
10. Substring Replace with None Check
Write a Python function that replaces all occurrences of a substring in a string with another substring. Returns None if the original string is empty.
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