Print , Function Parameters and 'Return'
The most used build-in fuinction for debugging and another essential thing about functions
Homework from Last Time (if you didn't do last lesson , ignore this)

When working with strings you can see that they can only be added and only multiplied.
When you add an int with a float , result is a float and when you make a calculate with all 5 basic operators , you will see that exponent happens first , then division , then multiplication then addition.
Print built-in function
How do we get input into it?
As I said last tutorial, print can take a max number of parameters that's equal to 255, because it uses special stuff we won't cover . When you do print(5+5) you actually put only 1 parameter , when you do print("word " + "word") it's still 1 parameter used.
Why would I care how many parameters I use in print?
Well let's say you want to print a string and an int in the same parameter , there are ways to get around like print("word" + str(10)) [this outputs word10]
If you want the output to be "word 10" you can change the "word" to "word " , but there's a easier way than using str() and adding a space to the string. Do print("word", 10) . This outputs "word 10" and it's faster and easier to use.
Function Parameters
What are they and why would I care?
Well if you will ever make a function and that function needs to take an existing variable that changes everytime , you should know what parameters are.
Recently as I talked about print , you probably noticed that you give it parameters and the parameters are separated by a ,
How do I make use of them in MY OWN function?
We'll start by defining our function , I hope you got used to indent when making functions , I'll also screenshot to make sure you got it. So you probably know that when you define a function you start by writting def name_of_the_function(parameters): well I don't expect you to know that parameters where the ones that go in the parenthesis . Let's make a function to print it's parameter then we gonna do a little more complex.
def nice_name(what_to_print):
print(what_to_print)
Now that we defined out function , we will have to call it like this nice_name(variable_we_will_use) , of course instead of variable_we_will_use , we will use a variable we will define before our function. We'll make a variable called i_want_to_print_this = "this is a more than a word"
Now try to run the script and the output will be "this is more than a word " , if it doesnt work for you , take a look at this screenshot:

'Return' inside a function
Why do I need it?
Let's say you want to make a function that won't print the result , but give you back another value for a variable. In that case we will make use of return .
How do I use it myself ?
The syntax is pretty simple , but first I'll give you an example that's been used a lot in the return examples. Let's say we need to make a function that will calculate A + B [A and B will be parameters]

We made a function called "add_2_numbers" and we made it need 2 parameters. The function will then stopped and give us the result "a+b"
We can also use this function to make a variable get the new value:

Practice makes PERFECT!
For homework this time , I'll ask you make a function with 3 parameters that will multiply first 2 , then subtract the third one with the result of first 2. The answers will be shown at the start of the next lesson in case you are stuck.
You have finished most of the basics , there are still some basic stuff to learn .
I also want to thank you for the amount of upvotes on discord server [Coding Lessons], it lets me know I should continue making them. Keep up the good work!
Last updated
Was this helpful?