Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Hi! John\n",
- "Hi! Nick\n"
- ]
- }
- ],
- "source": [
- "def greet(msg, name):\n",
- " print(msg + ' ' + name)\n",
- " \n",
- "def greet_hi(name):\n",
- " return greet('Hi!', name)\n",
- "\n",
- "greet_hi('John')\n",
- "greet_hi('Nick')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Hola! John\n",
- "Hola! Nick\n"
- ]
- }
- ],
- "source": [
- "from functools import partial\n",
- "greet_hola = partial(greet, msg='Hola!')\n",
- "\n",
- "greet_hola(name='John')\n",
- "greet_hola(name='Nick')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "25\n",
- "125\n"
- ]
- }
- ],
- "source": [
- "def pow(base, exponent):\n",
- " print(base ** exponent)\n",
- "\n",
- "square = partial(pow, exponent=2)\n",
- "cube = partial(pow, exponent=3)\n",
- "\n",
- "square(5)\n",
- "cube(5)"
- ]
- }
- ],
- "metadata": {
- "kernelspec": {
- "display_name": "Python 3",
- "language": "python",
- "name": "python3"
- },
- "language_info": {
- "codemirror_mode": {
- "name": "ipython",
- "version": 3
- },
- "file_extension": ".py",
- "mimetype": "text/x-python",
- "name": "python",
- "nbconvert_exporter": "python",
- "pygments_lexer": "ipython3",
- "version": "3.5.2"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment