Commit d3201417 authored by Loic Huder's avatar Loic Huder
Browse files

Added snippet for EAFP at the end of pres02

parent b74668c3
Pipeline #32980 passed with stage
in 52 seconds
......@@ -2615,6 +2615,40 @@
"In this particular case, using `try` and `except` is far easier !"
]
},
{
"cell_type": "code",
"execution_count": 82,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hello is not a int\n",
"hello is not a float\n",
"1.5 is not a int\n",
"['hello', 1.5, 2]\n"
]
}
],
"source": [
"split_list = []\n",
"for value in str_variables.split(\"\\n\"):\n",
" if value.isdecimal():\n",
" value = int(value)\n",
" else: \n",
" print(value, \"is not a int\")\n",
" int_part, sep, dec_part = value.partition('.')\n",
" if int_part.isdecimal() and dec_part.isdecimal():\n",
" value = float(value)\n",
" else:\n",
" print(value, 'is not a float')\n",
" split_list.append(value)\n",
"\n",
" \n",
"print(split_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
......
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