Notizen
functions in python
Inhalt der Notizen (2)
Seite 1
"functions in python"
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
Creating a Function:
-------------------------------
In Python a function is defined using the def keyword:
Example:
def my_function():
print("Hello from a function")
Calling a Function:
----------------------------
example:
def my_function():
print("Hello from a function")
my_function()
output:
Hello from a function
Parameters:
-----------------
Information can be passed to functions as parameter.
Parameters are specified after the function name, inside the parentheses. You can add as many parameters as you want, just separate them with a comma.
The following example has a function with one parameter (fname). When the function is called, we pass along a first name, which is used inside the function to print the full name:
def my_function(fname):
print(fname + " Refsnes")
my_function("Emil")
my_function("Tobias")
my_function("Linus")
output:
-----------
Emil Refsnes
Tobias Refsnes
Linus Refsnes
Seite 2
Informationen
- Beschreibung
- Notiz am functions in python, erstellt von Sandeep Sunny am 05/08/2019.
- Erstellt von
- Sandeep Sunny · Aug 2019
- Aktualisiert
- 5 Aug 2019
- Aufrufe
- 4
- Tags
- Bewertung