Code: Select all
$ list = ['apples','oranges']
"I'm gonna making apple sauce and orange juice."
$list.remove("apples")
$list.remove("oranges")
"The list is empty."
if list == []:
"I need to buy apples and oranges."
Code: Select all
$ list = ['apples','oranges']
"I'm gonna making apple sauce and orange juice."
$list.remove("apples")
$list.remove("oranges")
"The list is empty."
if list == []:
"I need to buy apples and oranges."
technically, python treats its data types as booleans (True or False)... python magically understands when to consider a data type False or True...lovebby wrote: ↑Tue Apr 21, 2020 5:42 am So I'm essentially trying to get this code working.
Is there a way to check if the list is empty?Code: Select all
$ list = ['apples','oranges'] "I'm gonna making apple sauce and orange juice." $list.remove("apples") $list.remove("oranges") "The list is empty." if list == []: "I need to buy apples and oranges."
Code: Select all
default my_list = []
label start:
if my_list: # this is equivalent to `my_list == []`, you can reverse the condition by setting it to `not my_list`, which is equal to `my_list != []`
"Your list has one or more elements."
else:
"Your list is empty."
lovebby wrote: ↑Tue Apr 21, 2020 5:42 am So I'm essentially trying to get this code working.
Is there a way to check if the list is empty?Code: Select all
$ list = ['apples','oranges'] "I'm gonna making apple sauce and orange juice." $list.remove("apples") $list.remove("oranges") "The list is empty." if list == []: "I need to buy apples and oranges."
Code: Select all
$ test_list = ['apples','oranges']
"I'm gonna making apple sauce and orange juice."
$ del test_list[0]
$ del test_list[0]
"This list is empty"
if len(test_list) == 0:
"I need to buy apples and oranges."
else:
"This list is not empty."
Code: Select all
python:
def isEmptyList(your_list):
if len(your_list) == 0:
return True
return False
Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]