## Tuesday, September 3, 2019

Solution Exercise 28: try if a list or string is empty with python

#### Exercise 28

Write a Python program that tests whether a list is empty or not. Same question for a string of characters.

### First method

Try if a list is empty
``````# define a list L
L = list()

# try if the list L is empty
if L == []:
print("The list  L is empty")
else:
print("The list L is not  empty")
``````
Try if a string is empty
``````# define a string s
s=""

# try if the string s is empty
if s == "":
print("The string s  is empty")
else:
print("The list s is not  empty")
``````

### Second Method

Try if a list is empty
``````# define a list L
L = list()

# try if the list L is empty by using the len() function
if len(L) == 0:
print("The list  L is empty")
else:
print("The list  L is not  empty")
``````
Try if a string is empty
``````# define a string s
s=""

# try if the string s is empty by using the len() function
if len(s) == 0:
print("The string s  is empty")
else:
print("The list s is not  empty")
``````

Younes Derfoufi

## Python Exercises With Solutions

1. Python Arithmetic Exercises
2. Equations & System Of Equations
3. Polynomials and Functions
4. Python Arithmetic Exercises
5. Numpy, Matplolib, Sympy , Scipy - Exercises
6. Python Arithmetic Exercises

Younes Derfoufi

## Sample Text 