w3resource

Python None data type exercises with solutions

Python None Data Type [ 10 exercises with solution ]

[An editor is available at the bottom of the page to write and execute the scripts.   Go to the editor]

1. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/extended-data-types/index_none.php