+ 4
Functions
How to execute functions without storing anything in a variable?
12 Answers
+ 3
I think that's an error, you define a function named 'fruit' and you also create a list named fruit. The compiler will be confused between the two because you want to print the list at the same time you also need to make sense of function, and you cant do that if both of them have same name. Your list has no quotation marks, so that's also an error.
fruits = ["apple," pear"]
def basket():
print(fruits)
basket()
You can also think function as "containers" since its reusable, so I rename the function basket. To call a function, you have to call it just like I did at the end of this code.
+ 4
can you give an example of a code snippet that you want to rewrite? there's nothing wrong with using a variable
+ 1
fruits is a list, not a function
remember to use the "" for strings:
fruits = ["apple", "banana"]
print(fruits)
+ 1
print(fruits)
we do not need a function
what should your function do? what should the output look like?
+ 1
Thank you!
Now it's working
0
fruits = [apple, pear]
def fruits():
print(fruits)
0
How can I execute that
0
If fruits would be the Name of the function I mean
0
and what is fruits = [...] in your example?
0
The variable for print
0
It was only an example
0
-> what should the output look like?