





























Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!






























Last updated on 28/07/2020 09:
FUNCTIONS
1. Title
Functions def function_name(): … …
… … function_name() … function_name() beginnerspython3/chapter
1. Title
Built in and user defined functions
1. Function, definition and structure Title def print_msg(): print( 'Hello World!' ) print_msg() def print_my_msg(msg): print(msg) print_my_msg( 'Hello World' ) def square(n: int) - > int: return n * n # Store result from square in a variable result = square(n= 4 ) print(result)
FUNCTIONS
1. Named/keyword arguments Title
def make_list_of_range(start: int, end: int) - > list: """ Makes a list of consecutive integers between start and end :param start: first integer :param end: last ingeter :return: a list with consecutive integers """ new_list = list(range(start, end)) return new_list make_list_of_range(start= 2 , end= 4 ) make_list_of_range(end= 2 , start= 4 ) prog_1/functions/parameters_example.py Keyword arguments
1. Named/keyword arguments Title
def make_list_of_range(start: int, end: int) - > list: """ Makes a list of consecutive integers between start and end :param start: first integer :param end: last ingeter :return: a list with consecutive integers """ newList = list(range(start, end)) return newList make_list_of_range( 2 , 4 ) prog_1/functions/parameters_example.py Positional arguments
1. Default values Title
def make_list_of_range_default(start: int, end: int = 10 ) - > list: """ Makes a list of consecutive integers between start and end :param start: first integer :param end: last integer :return: a list with consecutive integers """ newList = list(range(start, end)) return newList make_list_of_range_default( 2 ) prog_1/functions/parameters_example.py
1. Default values Title
1. Title
Return, multiple values def swap(a: int, b: int) - > tuple[int, int]: return b, a a = 2 b = 3 x, y = swap(a, b) print(x, ',' , y)
FUNCTIONS
1. Docstring and annotation (type hinting) Title def make_a_list_annotated(start: int, end: int) - > List: """ Makes a list of consecutive integers between start and end :param start: first integer :param end: last integer :return: a list with consecutive integers """ new_list = list(range(start, end)) return new_list beginnerspython3/chapter11/helloworldfunction.py
1. Docstring and annotation (type hinting) Title def make_a_list_of_range_default(start: int, end: int = 10) - > list: """ Makes a list of consecutive integers between start and end :param start: first integer :param end: last integer :return: a list with consecutive integers """ new_list = list(range(start, end)) return new_list beginnerspython3/chapter11/helloworldfunction.py