# Def function(help)

#1
Need help for def function

## I need some help with syntax of the 'def' function.

I think that I understand the basic concept of the 'def' function, but I feel like I might need somethings cleared up. I just need a basic understanding of it, some help understanding why it's necessary in python, and some help understanding why, in this exercise (Learn Python: Functions/Parameters and Arguments), you need to 'define' power. I need someone to better explain it to me because it's a little bit confusing... I'd appreciate a little help! Thank you!

#2

Itās not a function, itās a statement that creates a function and assigns a name to it

#3

Since weāre on the topic. Can you explain to me the difference between āfunctionsā and āstatementsā, since Iāve clearly mixed the two of them up?

#4

Nothing in common. Functions are callable values. A statement is an instruction to do something which will have some side effect, thereās no result of a statement itself (for-statement, if-statement, function-statementā¦) In contrast, an expression evaluates to a value: 1 evaluates to 1, 1+1 evaluates to 2, a function call evaluates to the value that the function returns. Expressions have results, but typically no side-effects (but some do)
For example, 1+1 doesnāt cause anything to be printed (side effect) but it has a result of 2

#5

Also, couldnāt you just do something like, base = 37 and exponent = 4 instead of def power(base, exponent) and power(37, 4). Side-note: The āandā isnāt meant to be any sort of code in these examples.

#6

You might actually find it difficult to come up with a trivial function that isnāt already better expressed better in some other way in python with all the built-in ways of expressing common actions

#7

Actually Iām not even sure what you mean by āsomething elseā
The point of functions is to abstract away grimy details.
You would for example not want to do addition one digit at a time and carry the one yourself, youād use an add function (or operator, same thing for the most part)
And, as mentioned, theyāre values, which starts blurring the line between data and code

#8

Alright, so functions are practically words and stuff you can add values to, such as x = 4, if Iām not mistaken. And what you said in your previous comment responding to my question, is basically just that the def statement is kind of a shortcut? Iām kinda just guessing here based on what I picked up.

#9

No. That doesnāt really add up at all

#10

What? The last part? I knew I was probably wrong about the last part.

#11

Any of it. With a total lack of sense for what they are, wikipedia is a good place to start

#12

Hmmmā¦ I mean I am searching it up as youāre talkingā¦

#13

Oh ok nvm. I found some things describing functions better.

#14

A little bit at least.

#15

Sorry! Iām a little rusty and Iāve forgotten things from the beginning of the Python lesson on CodeCademyā¦ I got confused because on the lesson I was on we were ācreating our own functionsā with define so I kinda lost the definitions of all this vocab! Iāve gone back through the lessons several times already as review but I guess itās back again to the reviews againā¦

#16

If you focus on what you can do and donāt even try to remember how to write the corresponding code, youāll have far less to memorize

Youād then decide what you want to do, and look up how those actions are done.

For example, numbers support addition, subtraction etc. Loops allow you to repeat things. Lists behave pretty much like a list you write on paper. Variables hold on to values for later use.
ā¦

#17

RIght[quote=āionatan, post:2, topic:321852, full:trueā]
Itās not a function, itās a statement that creates a function and assigns a name to it
[/quote]

Right because you needs to have more detail

#18

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.