Skip to content

Chapter 8

Jarlin Almanzar edited this page Nov 22, 2019 · 3 revisions

Functions

def greet_user():
    """Display a simple greeting"""
    print("Hello!")

greet_user()

Passing multiple values

def greet_user(*names):
    """Display a simple greeting with names"""
    print(*names)

greet_user('Jarlin', 'Billy')

Passing values within a dict

def greet_user(name, age, **user_info):
    """Create and display a dict"""
    user_info['user_name'] = name
    user_info['user_age'] = age

    print(user_info)

greet_user('Jarlin', 'Billy')

Modules

A module is a file ending in .py that contains the code you want to import into your program.
An import statement tells python to make the code in a module available in the currently running program.

How to import

example: name_of_file.py

import name_of_file

# How to use
name_of_file.name_of_method()

Import a specific function

from name_of_file import *
Clone this wiki locally