Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lära Defining Functions | Functions and Modules
Introduction to Data Analysis in Python
course content

Kursinnehåll

Introduction to Data Analysis in Python

Introduction to Data Analysis in Python

1. Basics
2. Data Types
3. Control Flow
4. Functions and Modules
5. Introduction to NumPy

book
Defining Functions

You can define your own functions if some parts of code need to be repeated during a program's execution.

To define a function, use the def keyword followed by function name. Then, within the parentheses set function parameters. Next, put a colon sign, and define instructions that function should do (these lines must be indentated). If you want your function to return something, use the return keyword. The instructions within the function are called function body. For example,

12345678910
# Defining simple function with two parameters def discount(price, discount_percent):     print("Initial price:", price)     print("Discount:", discount_percent, "%")     new_price = price * (1-discount_percent/100)     print("New price:", new_price) # Calling function discount(100, 15) discount(270, 25)
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 5

Fråga AI

expand
ChatGPT

Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal

course content

Kursinnehåll

Introduction to Data Analysis in Python

Introduction to Data Analysis in Python

1. Basics
2. Data Types
3. Control Flow
4. Functions and Modules
5. Introduction to NumPy

book
Defining Functions

You can define your own functions if some parts of code need to be repeated during a program's execution.

To define a function, use the def keyword followed by function name. Then, within the parentheses set function parameters. Next, put a colon sign, and define instructions that function should do (these lines must be indentated). If you want your function to return something, use the return keyword. The instructions within the function are called function body. For example,

12345678910
# Defining simple function with two parameters def discount(price, discount_percent):     print("Initial price:", price)     print("Discount:", discount_percent, "%")     new_price = price * (1-discount_percent/100)     print("New price:", new_price) # Calling function discount(100, 15) discount(270, 25)
copy

Var allt tydligt?

Hur kan vi förbättra det?

Tack för dina kommentarer!

Avsnitt 4. Kapitel 5
Vi beklagar att något gick fel. Vad hände?
some-alt