Commit 2820c217 by Arucas Chacon

### Empty notebooks

parent 665dbfe4
\n", "
\n", "

Exercise - Types

\n", "
\n", "
\n", " What type of value is 3.4?
\n", " What type of value is 3.25 + 4?
\n", " What type of value is 4/2?
\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Exercise - Division Types

\n", "
\n", "
\n", "In Python 3, the // operator performs integer (whole-number) floor division, the / operator performs floating-point division, and the ‘%’ (or modulo) operator calculates and returns the remainder from integer division.
\n", "\n", "However in Python2 (and other languages), the / operator between two integer types perform a floor (//) division. To perform a float division, we have to convert one of the integers to float\n", "
\n", "
\n" ] }, { "cell_type": "raw", "metadata": {}, "source": [ "print('5 // 3 =', 5//3)\n", "print('5 / 3 =', 5/3)\n", "print('5 % 3 =', 5%3)\n", "print('float(5)/3 =', float(5) / 3 )\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "\n", "
\n", "
\n", "

Exercise - Arithmetic with Different Types

\n", "
\n", "
\n", " Which of the following will print 2.0? Note: there may be more than one right answer.
\n", " first = 1.0
\n", "second = \"1\"
\n", "third = \"1.1\"
\n", "
\n", "
\n", "1. first + float(second)
\n", "2. float(second) + float(third)
\n", "3. first + int(third)
\n", "4. first + int(float(third))
\n", "5. int(first) + int(float(third))
\n", "6. 2.0 * second\n", "
\n", "
\n", "\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "

Key Points

\n", "
\n", "
\n", "
\n", "
• Every value has a type.
• \n", "
• Use the built-in function type() to find the type of a value.
• \n", "
• Types control what operations can be done on values.
• \n", "
• Strings can be added and multiplied.
• \n", "
• Strings have a length (but numbers don’t).
• \n", "
• Must convert numbers to strings or vice versa when operating on them.
• \n", "
• Must convert numbers to strings or vice versa when operating on them.
• \n", "
• Can mix integers and floats freely in operations.
• \n", "
\n", "
\n", "
\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.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }
\n", "
\n", "

Key Points

\n", "
\n", "
\n", "
\n", "
• \n", "
• A function may take zero or more arguments.
• \n", "
• Commonly-used built-in functions include max, min, and round.
• \n", "
• Functions may have default values for some arguments.
• \n", "
• Use the built-in function help to get help for a function.
• \n", "
• The Jupyter Notebook has two ways more to get help.
• \n", "
• Every function returns something.
• \n", "
\n", "
\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.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }