#๐Ÿ”’ Def

151 messages ยท Page 1 of 1 (latest)

muted pebble
#

Def thing I don't understand

lavish sentinelBOT
#

@muted pebble

Python help channel opened

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.

zenith jungle
#

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?

hoary shadow
#

!d def

lavish sentinelBOT
muted pebble
zenith jungle
#

Don't stray from the discussion

muted pebble
zenith jungle
#

Is there anything I've said so far that you don't understand?

hoary shadow
#

have you used print()

zenith jungle
hoary shadow
#

no i just wanted to say that thats a function, so they already know how to use functions just not how to make em

zenith jungle
#

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?

zenith jungle
muted pebble
hoary shadow
#

this has nothing to do with math

muted pebble
zenith jungle
#

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

zenith jungle
muted pebble
zenith jungle
#

Ok great

pallid sparrow
zenith jungle
#

I'll explain what parameters are in a moment. For now, I'm just showing you how we structure a function

zenith jungle
#

Please let me focus on what I'm doing

pallid sparrow
zenith jungle
#

and I've already dispelled that

pallid sparrow
#

My bad. I will let you take it

zenith jungle
#

Here's another function.

#

What's the name of this function?

muted pebble
zenith jungle
#

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.

muted pebble
zenith jungle
#

yes

muted pebble
zenith jungle
#

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?

zenith jungle
#

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?

muted pebble
#

Even though I only speak English

zenith jungle
#

I'm not sure how to simplify that question

winged quest
#

@muted pebble stop talking about how incompetent you think you are. Please actually try, or let people have their time back.

zenith jungle
#

Realistically, if you struggle with english, you'll struggle with python too

#

The answer would be to improve your english first

hoary shadow
# muted pebble Even though I only speak English

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()
```||
muted pebble
zenith jungle
#

Let's get back to my previous question

hexed pike
winged quest
#

Everyone should let Fashoomp work their magic.

zenith jungle
#

Study and practice. That's how you learn everything

#

but you're getting off topic again and again

muted pebble
muted pebble
#

I'll try even harder

zenith jungle
#

Have you seen the len function in python yet?

zenith jungle
#

Do you understand what a string is in python?

muted pebble
hoary shadow
#

you already understand print() tho right?

zenith jungle
zenith jungle
muted pebble
zenith jungle
# muted pebble ("")???

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

hoary shadow
zenith jungle
#

If we want to know how many letters a string has, we can use the len function

#
print(len("hello"))
winged quest
#

@hoary shadow Fashoomp is doing python help surgery here. Please let them do it

zenith jungle
#

@muted pebble what do you think the result of this is?

hoary shadow
#

-# i just pinged their own message btw nothing mine

zenith jungle
muted pebble
zenith jungle
#

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?

muted pebble
zenith jungle
#

we have to put exactly one piece of information inside

muted pebble
zenith jungle
#

I didn't use any numbers in my example. Where did you get that from?

zenith jungle
#

Ok, so does it makes sense then?

muted pebble
hoary shadow
zenith jungle
hoary shadow
#

right

zenith jungle
#

"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?

muted pebble
#

My brain is burnt out RN can I get a break for rn?

hoary shadow
ebon charm
hoary shadow
#

nop

ebon charm
zenith jungle
hoary shadow
ebon charm
#

arguments in the function call are mapped to parameters in the function definition . this is standard.

hoary shadow
#

or reading stuff up yeah

zenith jungle
#

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

hoary shadow
#

lol same xD but learned it after talking to people explainig my code or vice versa

ebon charm
zenith jungle
#

yeah exactly

#

they do have specific meanings, but if I said "your function call is missing its parameters", it would still make sense

ebon charm
zenith jungle
#

Haha I never even thought about args/kwargs being "misnamed"

ebon charm
#

parms/kwparms? ugh

zenith jungle
#

yuck

tropic perch
#

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.

ebon charm
#

yes

lavish sentinelBOT
#
Python help channel closed for inactivity

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.