Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Alexon-Abreu/8d8f9e2c033870ce89707410ea5fdde3 to your computer and use it in GitHub Desktop.
Save Alexon-Abreu/8d8f9e2c033870ce89707410ea5fdde3 to your computer and use it in GitHub Desktop.
Created on Skills Network Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center>\n",
" <img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/Logos/organization_logo/organization_logo.png\" width=\"300\" alt=\"cognitiveclass.ai logo\" />\n",
"</center>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>Create a Tuple</h3>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"create the Tuple <code> (0,1,2,3) </code> and assign it to the variable <code> A </code>:\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, 1, 2, 3)\n"
]
}
],
"source": [
"A = (0,1,2,3)\n",
"print (A)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details><summary>Click here for the solution</summary>\n",
"\n",
"```python\n",
"A = (0,1,2,3)\n",
"print(A)\n",
"```\n",
"\n",
"</details>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>Find the elements of a Tuple</h3> \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the first two elements of the Tuple <code> A </code>:\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(0, 1)\n"
]
}
],
"source": [
"A [0:2]\n",
"print (A[0:2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details><summary>Click here for the solution</summary>\n",
"\n",
"```python\n",
"A[0:2]\n",
"```\n",
"\n",
"</details>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>Lists </h3> \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the next few questions, you will need the following list:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"B=[\"a\",\"b\",\"c\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the first two elements of the list <code> B</code>:\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['a', 'b']\n"
]
}
],
"source": [
"B=[\"a\",\"b\",\"c\"]\n",
"print (B[0:2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details><summary>Click here for the solution</summary>\n",
"\n",
"```python\n",
"B[0:2]\n",
"```\n",
"\n",
"</details>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Change the first element of the list to an uppercase <code> \"A\" </code> \n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['A', 'b', 'c']\n"
]
}
],
"source": [
"B=[\"a\",\"b\",\"c\"]\n",
"B[0] = 'A'\n",
"print (B)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details><summary>Click here for the solution</summary>\n",
"\n",
"```python\n",
"B[0] = 'A'\n",
"print(B)\n",
"```\n",
"\n",
"</details>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"\n",
"<h3 align=\"center\"> © IBM Corporation 2020. All rights reserved. <h3/>\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment