Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "## Functions in python"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "5\n"
- ]
- }
- ],
- "source": [
- "def add(a,b):\n",
- " return (a+b)\n",
- "c=add(2,3)\n",
- "print(c)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "12\n",
- "omkaromkar\n"
- ]
- }
- ],
- "source": [
- "def mult(a,b):\n",
- " \n",
- " d=a*b\n",
- " return d\n",
- "print(mult(3,4))\n",
- "print(mult(2, \"omkar\"))\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "omkar kadam\n"
- ]
- }
- ],
- "source": [
- "def con (a,b):\n",
- " return(a + b)\n",
- "print(con(\"omkar \" ,\"kadam\"))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[0.2, 2, 3.4, 5, 6, 8, 9, 9.4, 10]\n",
- "[0.2, 2, 3.4, 5, 6, 8, 9, 9.4, 10]\n"
- ]
- }
- ],
- "source": [
- "album_rating=[10,2,3.4,5,8,6,9,0.2,9.4]\n",
- "sum(album_rating)\n",
- "len(album_rating)\n",
- "\n",
- "new=sorted(album_rating)\n",
- "print(new)\n",
- "\n",
- "album_rating.sort()\n",
- "print(album_rating)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": [
- "#Global variable inside function scope\n",
- "var=\"GOT\"\n",
- "def fun(var):\n",
- " global new_var\n",
- " new_var = \" is shitty\"\n",
- " return(var+new_var)\n",
- "print(fun(var))\n",
- "print(new_var)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "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.6.8"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement