#๐ Def
151 messages ยท Page 1 of 1 (latest)
@muted pebble
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.
Ok. def is the python keyword for defining a function
a "function" is just a block of code that we can use later on
it's very useful when we want to re-use a specific block of code
Does this make sense?
!d def
8.7. Function definitions
A function definition defines a user-defined function object (see section The standard type hierarchy):
I have a hard time communicating with programmers
Only answer the questions I ask you
Don't stray from the discussion
Alr
Is there anything I've said so far that you don't understand?
have you used print()
Let's avoid too many cooks for now
no i just wanted to say that thats a function, so they already know how to use functions just not how to make em
Ok great, let's continue
when we define a function, we give it a name, as well as any required "parameters"
We don't have to give our function any parameters. It really depends on what kind of function you're trying to create
Here's an example of a function with no parameters
def my_function():
...
@muted pebble What is the name of this function?
My_function?
Yes, and how many parameters does it have?
I'm at 1st grade lvl math I suck at math
this has nothing to do with math
What's a parameter.????
This has nothing to do with math. If you've read what I've said so far, you should be able to answer my question
What does this say here?
No premeters
Ok great
Parameters are just variables of functions (like x = 2) they get values (called as arguments) whenever you call the function.
for example:
def my_function(x):
print(x)
my_function(2)
I'll explain what parameters are in a moment. For now, I'm just showing you how we structure a function
I'm trying not to overwhelm, I'm taking this slow
Please let me focus on what I'm doing
I think mellow thought of term parameters is coming from math
and I've already dispelled that
My bad. I will let you take it
def function_two(param1):
...
Here's another function.
What's the name of this function?
Function_two?
yes exactly
but this time, it has a parameter
This is how we define the required parameters for our function
we can include as many as we want or need
def many_parameters_func(p1, p2, p3, p4):
...
if we want 4 parameters, we can do this
The names are just like variables. We can name them whatever we want.
The p are parameters?
yes
Alr
Ok, now remember, a function is a block of code that we can use later on
to use the function after we define it, we "call" the function
as wild pointed out earlier, print() is an example
print is a function
print() is how we call it
we "call" a function by using the function's name followed by ()
Is there anything there you don't understand?
No
Ok, print is a special exception in how it handles parameters so I won't continue talking about it for now
Have you seen the len function yet?
My English understanding is low grade
Even though I only speak English
I'm not sure how to simplify that question
@muted pebble stop talking about how incompetent you think you are. Please actually try, or let people have their time back.
Realistically, if you struggle with english, you'll struggle with python too
The answer would be to improve your english first
heres an example of a convo in very basic english.. you literally only use functions when you wanna reuse your code..
||
def express_sorrow():
print("im so sorry about that")
def express_thanks():
print("thanks you're the best")
def express_excitm():
print("thats amazingly awsome")
# now you could just use them anywhere in your code without typing all that again
# example
print("x said to y my watch got stolen y replied:")
express_sorrow()
print("y said to x my pan also got stolen yesterday x said")
express_sorrow()
print("but it wasn't really stolen it uwas under my bed, y responded by saying:")
express_excitm()
```||
Brruuuuuuuuuuuuuuuuuuu
Let's avoid giant blocks of code for now
Let's get back to my previous question
try to approach using games (trust me)
How do I learn English?
Everyone should let Fashoomp work their magic.
Study and practice. That's how you learn everything
but you're getting off topic again and again
Too much to learn bruh
let's go on topic
I'll try even harder
Have you seen the len function in python yet?
No
Do you understand what a string is in python?
I heard of it but I don't fully understand it
you already understand print() tho right?
Try and explain it to me with what you know
one thing at a time
("")???
string is how we represent text in python, and yes, we use "" around it to show that it's a string
"hello" is an example of a string
"goodbye" is an example of a string
Sometime we want to know how many letters are in a string
yes with no () or ??? () is for #1475322281520660581 message as mentioned above
Please stop veering them away from my questions
If we want to know how many letters a string has, we can use the len function
print(len("hello"))
@hoary shadow Fashoomp is doing python help surgery here. Please let them do it
@muted pebble what do you think the result of this is?
-# i just pinged their own message btw nothing mine
It prints Hello?
I just explained above what len does
.
5?
yes exactly ๐
we can say the len function has "one parameter"
len()
len('abc', 'xyz')
We can't use len like this
len() with nothing inside the () doesn't make sense to python
len('abc', 'xyz') has too much information, and also doesn't make sense to python
Does that make sense to you?
So we can't put anything in len() ?
we have to put exactly one piece of information inside
Only numbers?
I didn't use any numbers in my example. Where did you get that from?
Oh idk
Ok, so does it makes sense then?
Yes
because it returns number?
Sure but I never used any numbers in my arguments
right
Ok, so here's another term for you
"argument"
When we call a function, the information we provide inside the () are called the "arguments"
the arguments and parameters are related
When we define our function, we define the parameters. When we call our function, we provide 1 argument for each parameter
Any questions?
My brain is burnt out RN can I get a break for rn?
btw out of curiosity may i ask if you remember where did you first learn that term?
does "argument" seem unusual to you?
nop
your question is unusual
No idea, I've been using python for about 8+ years now
i used it way before knowing that its called "argument" then i learned that after talking to people...
arguments in the function call are mapped to parameters in the function definition . this is standard.
or reading stuff up yeah
I used to mix up parameter/argument and thought they were interchangeable terms
but it also can sort of be used interchangeably based on how you use them in a sentence
lol same xD but learned it after talking to people explainig my code or vice versa
in some ways they are interchangeable. If someone can say, "you're using the terms wrong" that means they knew what you meant, so why be pedantic?
yeah exactly
they do have specific meanings, but if I said "your function call is missing its parameters", it would still make sense
look at this issue and the three it links to: https://github.com/python/cpython/issues/133438
this one is 85 files and dozens of comments: https://github.com/python/cpython/pull/135160
Issue: PEP 3102 and PEP 570 should say Keyword-Only Parameters instead of Keyword-Only Argumentsย #133438
๐ Documentation preview ๐: https://cpython-previews--135160.org.readthedocs.build/
Haha I never even thought about args/kwargs being "misnamed"
parms/kwparms? ugh
yuck
The function is receiving a list of anonymous arguments and a dictionary of keyword arguments so naming those parameters that seems logical to me. The parameters, in this case, represent the arguments.
yes
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.