{ "metadata": { "name": "01_data_types" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "Data Types" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The main data types in python are:\n", "\n", "* Numbers;\n", "* String;\n", "* List;\n", "* Set;\n", "* Dictionary;" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Numbers" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Operators" ] }, { "cell_type": "code", "collapsed": false, "input": [ "2 + 3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "2 - 3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "2 * 3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "2**3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "2 / 3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "5 // 3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "5 % 3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A complete list of operators is in the [Python Documentation](http://docs.python.org/2/library/operator.html#mapping-operators-to-functions)" ] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Number types" ] }, { "cell_type": "code", "collapsed": false, "input": [ "2 / 3. # float" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "int(2 / 3.)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "int('1')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "float(1)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "float('1.3')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "long(1.300)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "complex(2, 3)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "complex('2+3j')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Assign a variable" ] }, { "cell_type": "code", "collapsed": false, "input": [ "one = 1" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Assign more than one variable at the same time" ] }, { "cell_type": "code", "collapsed": false, "input": [ "two, three, four = 2, 3, 4" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "print four, three" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "a = b = c = 1" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "a" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "b" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "c" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "#working only with python3\n", "a, *b, c = [1, 2, 3, 4, 5, 6]\n", "a == 1\n", "b == [2, 3, 4, 5]\n", "c == 6" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "complex0 = -3j # complex" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "complex0.imag" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "complex0.real" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "complex0**2" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "abs, pow, round" ] }, { "cell_type": "code", "collapsed": false, "input": [ "abs(-1.45)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "pow(2, 3)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To get more function we should load the [math library](http://docs.python.org/2/library/math)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import math\n", "round(math.pi, ndigits=3)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use python as a scientific calculator [1 minute]:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "x = 2 # assign a variable\n", "y = 3\n", "x * y" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "math.sin(math.pi/2.) # use functions and variables from the math library\n", "# if you import the math library with:\n", "# from math import *\n", "# become: sin(pi/2.)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Boolean" ] }, { "cell_type": "code", "collapsed": false, "input": [ "true = True\n", "false = False\n", "none = None\n", "one = 1\n", "zero = 0\n", "a = 'a'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "true is True # use \"is\" to check that is the same object" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "false is not True" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "true == True" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "one > zero # >/>=/ zero and zero > -one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "one < zero or zero < -one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "String" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To define a string we must use one of \",':" ] }, { "cell_type": "code", "collapsed": false, "input": [ "string ='qwertyuiopasdfghjklzxcvbnm'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In python we can see a string as an array of characters, the first element of a list index == 0 (Python as C and oder languages start from 0)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "string[0] # get the first element of the string" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "len(string) # get the lenght of the string" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "string[25] # get the last element of the string" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "string[-1] # get the last" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Slicing in python, we use \":\" to divide the start, finish and the step." ] }, { "cell_type": "code", "collapsed": false, "input": [ "string[0:6] # start=0, stop=6" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "string[::3] # step=3" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reverse the string using slice [1 minute]" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Solution:" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is possible to specify if the encoding system of the string is unicode starting the string definition with: 'u'" ] }, { "cell_type": "code", "collapsed": false, "input": [ "unicodestr = u'\u00e0\u00e8\u00e9\u00ec\u00e7\u00f2\u00f9'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "unicodestr[:3]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "print unicodestr[:3]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "String are not a modifiable object" ] }, { "cell_type": "code", "collapsed": false, "input": [ "numb = '0123-5678'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "numb[4]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we try to modify the fourth character python raise an error, because this operation are not allowed by the string class." ] }, { "cell_type": "code", "collapsed": false, "input": [ "numb[4] = 4" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mathematical operation with the strings, only summation and multiplication are allowed." ] }, { "cell_type": "code", "collapsed": false, "input": [ "'a'+'b'+'c'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'abc'-'c'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'a'*4" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Substitute the character '-' with '4' using the slice and the mathematical properties of the string class. [2 minutes]" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Possible solution" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To define a multirow string in python we simple need to add somewhere the character \"\\n\" inside the string" ] }, { "cell_type": "code", "collapsed": false, "input": [ "multirow = 'Things that I like in python:\\n - syntax;\\n - power.\\n'\n", "print multirow" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "multirow = \"\"\"Things that I like in python:\n", " - syntax;\n", " - power.\n", "\"\"\"\n", "print multirow" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "String as objects: some methods of the string class." ] }, { "cell_type": "code", "collapsed": false, "input": [ "findstr = \"find something inside\"" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "findstr.find('s')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "findstr[9:]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "findstr[9:].find('s')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "print(multirow.replace('syntax', \"it's nice\"))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "stripstr = ' some spaces '" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "stripstr.strip() # try the effect of: lstrip, rstrip" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "splitstr = \"split a long phrase, with a lot of words!\"" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "splitstr.split() # specify with character should be use to split the string, the defaul is ' '" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Play with the string using some other methods like: upper, capitalize, lower, isdigit, islower, etc. [2 minutes]" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "character = 'A strAngE strIng'\n", "character.lower()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "numbers = '1234'\n", "numbers.isdigit()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "String formatting with python as in C" ] }, { "cell_type": "code", "collapsed": false, "input": [ "'python is %s!!!' % 'beautiful'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "import math\n", "'number int: %05d, float: %f' % (15, math.pi)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'number int: %d, float: %05.2f' % (15, math.pi*100)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'list: %r' % [1,2,3,4]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "String formatting using the \"format\" method of the string class." ] }, { "cell_type": "code", "collapsed": false, "input": [ "'SELECT {cols} FROM {table}'.format(cols='cat, name', table='streets')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'SELECT {} FROM {}'.format('cat, name','streets')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the following variables:" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "integer = -12345\n", "double = 3.141592653589793\n", "word = 'python'" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "raw", "metadata": {}, "source": [ "Get the following strings [3 minutes]:\n", "\"Still missing: -12345 \u20ac\"\n", "\"the pigreco value is around: 3.14159\"\n", "\" python \"" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "List" ] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one = [\"a\", \"b\", \"c\", [1,2,3], \"d\"]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[1]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[0]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If we use a negative index we start from the last" ] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[-2]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the \":\" we separate the index of the first element, the last, and the step [first:last:step], these operation is called slicing." ] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[1:4]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[::2]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[::-1]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The list have some usefull methods, like:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.append('a')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.count('a')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "len(list_one)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.pop(-1)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.sort()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.index('b')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.extend(['e','f','g','h'])" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[0][0:0]=[0]\n", "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.insert(1, [4,5,6])\n", "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one[-3:]=[]\n", "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "list_one.remove('e')\n", "list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "'a' in list_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Tuple" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As a list but is unmodifiable" ] }, { "cell_type": "code", "collapsed": false, "input": [ "tuple_one = (1,2,3,':-)')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "tuple_one.index(2)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "tuple_one.count(':-)')" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "2 in tuple_one" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "tuple_one[0]" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "tuple_one[0] = 10" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Set" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Another data types that is available in python is \"set\"." ] }, { "cell_type": "code", "collapsed": false, "input": [ "gis = set(['arcgis', 'mapinfo', 'qgis', 'grass', 'udig'])\n", "opensource = set(['qgis', 'grass', 'udig'])\n", "usingpython = set(['qgis', 'grass', 'arcgis'])" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "gis - opensource" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "opensource & usingpython # and" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "opensource ^ usingpython # or" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Dictionary" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The last data type used in python that we see today is the dictionary, lets define a dictionary with the address number." ] }, { "cell_type": "code", "collapsed": false, "input": [ "contact = {'pietro': 333123808, 'jonh': 123123123}" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "contact['pietro']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "contact['pietro'] = {'cell': 333123808, 'tel': 04545454}" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "contact['pietro']['cell']" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 5" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Some dictionary methods: keys, values, items [1 minute]" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "contact.keys()" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Verify the type of an object" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add your contact into the the contact dictionary." ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To verify the type of an object we have some usefull function like:\n", "\n", "* type\n", "* isinstance" ] }, { "cell_type": "code", "collapsed": false, "input": [ "type(contact)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "type(1)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "isinstance(contact, dict)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Exercise 6" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Verify the type of the other objects that we have define untill now. [2 minutes]" ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }