Funktionen

Einführung in Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Funktionen

  • Nichts Neues!

  • type()

  • Ein Stück wiederverwendbarer Code

  • Löst eine bestimmte Aufgabe

  • Rufe lieber eine Funktion auf, statt selbst Code zu schreiben

Einführung in Python

Beispiel

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.012.png

Einführung in Python

Beispiel

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.013.png

Einführung in Python

Beispiel

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89

ch_3_1_slides.014.png

Einführung in Python

Beispiel

fam = [1.73, 1.68, 1.71, 1.89]
fam
[1.73, 1.68, 1.71, 1.89]
max(fam)
1.89
tallest = max(fam)
tallest
1.89
Einführung in Python

round()

round(1.68, 1)
1.7
round(1.68)
2
help(round) # Open up documentation
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative.
Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.026.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.027.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.028.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.029.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.030.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.031.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.032.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.033.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.034.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.035.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.036.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 

ch_3_1_slides.037.png

Einführung in Python

round()

help(round)
Help on built-in function round in module builtins:

round(number, ndigits=None)
    Round a number to a given precision in decimal digits.

    The return value is an integer if ndigits is omitted or None. 
    Otherwise the return value has the same type as the number. ndigits may be negative. 
  • round(number)
  • round(number, ndigits)
Einführung in Python

Funktionen finden

  • Woher soll man sie kennen?

  • Standardaufgabe -> wahrscheinlich gibt es bereits eine Funktion dafür!

  • Das Internet ist dein Freund

Einführung in Python

Lass uns üben!

Einführung in Python

Preparing Video For Download...