01-DataTypes&ControlFlow.ipynb

parent ef53495a
...@@ -78,6 +78,33 @@ ...@@ -78,6 +78,33 @@
"type (1.)" "type (1.)"
] ]
}, },
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'int'>\n",
"<class 'float'>\n",
"<class 'float'>\n",
"<class 'float'> 0\n"
]
}
],
"source": [
"a=1\n",
"print(type(a))\n",
"b=2.0\n",
"c=2\n",
"print(type(a+b))\n",
"print(type(a/b))\n",
"\n",
"print(type(a/c), int(a/c))"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
...@@ -130,22 +157,54 @@ ...@@ -130,22 +157,54 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 18,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"tuple" "text": [
"<class 'tuple'>\n"
] ]
}, },
"execution_count": 5, {
"ename": "TypeError",
"evalue": "'tuple' object does not support item assignment",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-18-e12d2c827d71>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mmitupla\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"hola mundo\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmitupla\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mmitupla\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m4\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
]
}
],
"source": [
"mitupla = (1,2,3, \"hola mundo\")\n",
"print(type(mitupla))\n",
"mitupla[1]=4"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'list'>\n",
"[1, 4, 3, 'hola mundo']\n"
]
} }
], ],
"source": [ "source": [
"type((1,2))" "milista = [1,2,3, \"hola mundo\"]\n",
"print(type(milista))\n",
"milista[1]=4\n",
"\n",
"print(milista)"
] ]
}, },
{ {
...@@ -206,22 +265,68 @@ ...@@ -206,22 +265,68 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 23,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "name": "stdout",
"text/plain": [ "output_type": "stream",
"dict" "text": [
"<class 'dict'>\n",
"<class 'list'>\n"
]
}
],
"source": [
"mid={\"mensaje\":1, \"men2\":4}\n",
"print(type(mid))\n",
"mid=[{\"mensaje\":1, \"men2\":4}]\n",
"print((type(mid)))"
] ]
}, },
"execution_count": 8, {
"cell_type": "code",
"execution_count": 42,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"('a', 1)\n",
"('b', 2)\n",
"('c', 3)\n",
"a\n",
"b\n",
"c\n",
"1\n",
"2\n",
"3\n",
"a 1\n",
"b 2\n",
"Beto\n",
"c 3\n",
"<class 'dict_items'>\n"
]
} }
], ],
"source": [ "source": [
"type({\"mensaje\":\"hola mundo\"})" "d={\"a\":1, \"b\":2, \"c\":3}\n",
"for i in d.items():\n",
" print(i)\n",
"\n",
"for k in d.keys():\n",
" print(k)\n",
"\n",
"for k in d.values():\n",
" print(k)\n",
"\n",
"for (k, v) in d.items():\n",
" print(k, v)\n",
" if k=='b':\n",
" print('Beto')\n",
"\n",
"print(type(d.items()))"
] ]
}, },
{ {
...@@ -457,23 +562,22 @@ ...@@ -457,23 +562,22 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 32,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"0\n", "a\n",
"1\n",
"2\n", "2\n",
"3\n", "5.0\n"
"4\n"
] ]
} }
], ],
"source": [ "source": [
"for i in range(5):\n", "l=[\"a\",2,5.0]\n",
"for i in l:\n",
" print(i)" " print(i)"
] ]
}, },
...@@ -855,16 +959,31 @@ ...@@ -855,16 +959,31 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 46,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'list'>\n",
"<class 'set'> {1, 2, 3, 4, 5}\n",
"<class 'list'> [1, 2, 3, 4, 5]\n"
]
}
],
"source": [ "source": [
"a = [1,2,2,3,3,3,3,4,5,5]" "a = [1,2,2,3,3,3,3,4,5,5]\n",
"print(type(a))\n",
"sa=set(a)\n",
"print(type(sa),sa)\n",
"a=list(sa)\n",
"print(type(a),a)"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 48,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -996,7 +1115,6 @@ ...@@ -996,7 +1115,6 @@
"def test_pangram():\n", "def test_pangram():\n",
" pangram = \"jovencillo emponzoñado de whisky , qué figurota exhibe !\"\n", " pangram = \"jovencillo emponzoñado de whisky , qué figurota exhibe !\"\n",
" nopangram = \"Agua pasa por mi casa\"\n", " nopangram = \"Agua pasa por mi casa\"\n",
"\n",
" print(\"OK\" if is_pangram(pangram) and not is_pangram(nopangram) else \"KO\")\n", " print(\"OK\" if is_pangram(pangram) and not is_pangram(nopangram) else \"KO\")\n",
"\n", "\n",
"def is_pangram(string):\n", "def is_pangram(string):\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment