Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imbingz/472e688529cf9ae03c2ee45d1726cbdc to your computer and use it in GitHub Desktop.
Save imbingz/472e688529cf9ae03c2ee45d1726cbdc to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>Create a Tuple</h3>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"create the Tuple <code> (0,1,2,3) </code> and assign it to the variable <code> A</code>:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(0, 1, 2, 3)"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = (0,1,2,3)\n",
"A"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>Find the elements of a Tuple</h3> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the first two elements of the Tuple <code> A </code>:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(0, 1)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A[0:2]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>Lists </h3> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For the next few questions, you will need the following list:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"B=[\"a\",\"b\",\"c\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the first two elements of the list <code> B</code>:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"['a', 'b']"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B=[\"a\",\"b\",\"c\"]\n",
"B[0:2]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Change the first element of the list to an uppercase <code> \"A\" </code> "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"['A', 'b', 'c']"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"B=[\"a\",\"b\",\"c\"]\n",
"B[0] = \"A\"\n",
"B"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<small>Copyright &copy; 2018 IBM Cognitive Class. This notebook and its source code are released under the terms of the [MIT License](https://cognitiveclass.ai/mit-license/).</small>"
]
}
],
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment