#đź”’ Why does some functions have : or () next to them?
15 messages · Page 1 of 1 (latest)
@hollow coral
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
this is so that you can pass data into your functions
for example
# 'a' and 'b' cannot be accessed here since it is outside the function
def func1():
a = 10 # These are defined inside the function, so they cannot be accessed outside the function
b = 20 # same here
c = func2(a, b) # but what we can do is pass those variables from inside this function to another function
def func2(a, b):
return a + b
All function definitions start with def and end with paramaeters in brackets (.......) and a final colon :
why only some? Have you seen some that don't have () or :?
def add(a,b):#defining the function,":" is a syntax,means u need to use it
c=a+b
return c
x=add(3,5)#when I do this it's called calling a function,then 3 and 5 goes and sits in 'a' and 'b' returns the sum which is c
def should not be capitalized, and we don't use ; in python
My bad typo
Well, we mostly don't use ; in python 🙂
sure, but it was unnecessary to have it at the end of the line like they had before the edit
Yea my bad I m on phone
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.