Introduction to Functions - Hsanokklis/2023-2024-Tech-journal GitHub Wiki

Functions for beginners

image

Calling the function:

This will print the function "hello_func"

image

  • This is what you should not do since if you have to change the strings you would have to go in manually and change all of them.

image

  • doing this is more efficient because if you need to change the string it will change it in all 4 of the times the function is called rather then you having to go in manually and change it all yourself.

image

  • The return command in the functions means that when the function is called it will output the string "Hello Function"

image

  • if you string .upper to the function it will make the text HELLO FUNCTION instead of Hello Function.

image

Customizing Functions with parameters

  • when you set a parameter in your function your have to set the parameter when you call your function or you will get and error

image

A parameter is the variable listed inside the parentheses in the function definition

An argument is the value that are sent to the function when it is called

https://www.w3schools.com/python/gloss_python_function_arguments.asp#:~:text=A%20parameter%20is%20the%20variable,function%20when%20it%20is%20called.

  • You can specify a default for a parameter if no argument is specified when the function is called

image

  • this is when both arguments are specified so it prints "Hi, Corey" in the terminal.

image