{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Happy 23rd Birthday!\n" ] } ], "source": [ "age = 23\n", "message = \"Happy \" + str(age) + \"rd Birthday!\"\n", "\n", "print(message)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Hello, Ada Lovelace!\n" ] } ], "source": [ "# %load chapter_02/name.py\n", "first_name = \"ada\"\n", "last_name = \"lovelace\"\n", "full_name = first_name + \" \" + last_name\n", "\n", "message = \"Hello, \" + full_name.title() + \"!\"\n", "print(message)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "14" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "def sum(a,b):\n", " return a + b\n", "sum(12,2)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['honda', 'yamaha', 'suzuki', 'ducati']\n", "['honda', 'yamaha', 'suzuki']\n", "\n", "A Ducati is too expensive for me.\n" ] } ], "source": [ "motorcycles = ['honda', 'yamaha', 'suzuki', 'ducati'] \n", "print(motorcycles)\n", "\n", "too_expensive = 'ducati'\n", "motorcycles.remove(too_expensive)\n", "print(motorcycles)\n", "print(\"\\nA \" + too_expensive.title() + \" is too expensive for me.\")\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']\n", "['dog', 'dog', 'goldfish', 'rabbit']\n" ] } ], "source": [ "pets = ['dog', 'cat', 'dog', 'goldfish', 'cat', 'rabbit', 'cat']\n", "print(pets)\n", "\n", "while 'cat' in pets:\n", " pets.remove('cat')\n", " \n", "print(pets)\n" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }