Skip to content

Instantly share code, notes, and snippets.

@Pankajnu
Last active September 26, 2020 17:13
Show Gist options
  • Select an option

  • Save Pankajnu/bd0836d8883765f07689c25332b61fe3 to your computer and use it in GitHub Desktop.

Select an option

Save Pankajnu/bd0836d8883765f07689c25332b61fe3 to your computer and use it in GitHub Desktop.
basics_day01.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name=\"Awesome\"",
"execution_count": 6,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "type(name)",
"execution_count": 8,
"outputs": [
{
"data": {
"text/plain": "str"
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "len(name)",
"execution_count": 9,
"outputs": [
{
"data": {
"text/plain": "7"
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name.lower()",
"execution_count": 10,
"outputs": [
{
"data": {
"text/plain": "'awesome'"
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name.capitalize()",
"execution_count": 13,
"outputs": [
{
"data": {
"text/plain": "'Awesome'"
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "\"this is\".capitalize()",
"execution_count": 14,
"outputs": [
{
"data": {
"text/plain": "'This is'"
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name.upper()",
"execution_count": 15,
"outputs": [
{
"data": {
"text/plain": "'AWESOME'"
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name[1]",
"execution_count": 28,
"outputs": [
{
"data": {
"text/plain": "'w'"
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name[-5:]",
"execution_count": 29,
"outputs": [
{
"data": {
"text/plain": "'esome'"
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "str(9)",
"execution_count": 30,
"outputs": [
{
"data": {
"text/plain": "'9'"
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "str(213)",
"execution_count": 31,
"outputs": [
{
"data": {
"text/plain": "'213'"
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "\"This \" + \"is\" + \" Awesome\"",
"execution_count": 33,
"outputs": [
{
"data": {
"text/plain": "'This is Awesome'"
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name.replace(\"t\",\"e\")",
"execution_count": 35,
"outputs": [
{
"data": {
"text/plain": "'Awesome'"
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name.replace(\"e\",\"FF\")",
"execution_count": 37,
"outputs": [
{
"data": {
"text/plain": "'AwFFsomFF'"
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "name.endswith(\"i\")",
"execution_count": 38,
"outputs": [
{
"data": {
"text/plain": "False"
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x=[1,2,3,4,5,6,212,434]",
"execution_count": 40,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x.append(2018)",
"execution_count": 47,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x.extend(\"this\")",
"execution_count": 48,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x=[1,2,3,4]",
"execution_count": 44,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "y=[\"A\",\"B\",\"C\"]",
"execution_count": 45,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x+y",
"execution_count": 46,
"outputs": [
{
"data": {
"text/plain": "[1, 2, 3, 4, 'A', 'B', 'C']"
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "if (5-5==0) and (6-6==1):\n print (\"yes\")\n print (\"this\")\nelif 6-5==2:\n print (\"yes\")\nelif 10/5==2:\n print (\"No\")\nelse:\n print (\"no other conditions satisfying\")\n ",
"execution_count": 56,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "No\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x\nfor i in x:\n print (x)\n ",
"execution_count": 59,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x=[1,2,3,4]",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in x:\n print(x)",
"execution_count": 60,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n[1, 2, 3, 4, 2018, 't', 'h', 'i', 's']\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in y:\n print(y)\n",
"execution_count": 61,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "['A', 'B', 'C']\n['A', 'B', 'C']\n['A', 'B', 'C']\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "x\nfor i in x:\n\n\n\n print(i)",
"execution_count": 79,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "1\n2\n3\n4\n2018\nt\nh\ni\ns\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in range (10,100,2):\n print (i)",
"execution_count": 81,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "10\n12\n14\n16\n18\n20\n22\n24\n26\n28\n30\n32\n34\n36\n38\n40\n42\n44\n46\n48\n50\n52\n54\n56\n58\n60\n62\n64\n66\n68\n70\n72\n74\n76\n78\n80\n82\n84\n86\n88\n90\n92\n94\n96\n98\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for x in range (10,100,2):\n print [x]",
"execution_count": 97,
"outputs": [
{
"ename": "TypeError",
"evalue": "'builtin_function_or_method' object is not subscriptable",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m<ipython-input-97-2a925b9ff811>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mrange\u001b[0m \u001b[1;33m(\u001b[0m\u001b[1;36m10\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m100\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mprint\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;31mTypeError\u001b[0m: 'builtin_function_or_method' object is not subscriptable"
]
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in range (5,8):\n print (i, i**2)",
"execution_count": 99,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "5 25\n6 36\n7 49\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in range(4):\n print (i)",
"execution_count": 103,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "0\n1\n2\n3\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in range (2 ** 2):\n print ('hello , world')",
"execution_count": 104,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "hello , world\nhello , world\nhello , world\nhello , world\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "nam = 0\nn = 5\nfor i in range (1, n+1):\n nam +=i\n print (nam)",
"execution_count": 108,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "1\n3\n6\n10\n15\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in range (10):\n print(i)",
"execution_count": 113,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "for i in range (5,50,5) :\n print(i)",
"execution_count": 117,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "5\n10\n15\n20\n25\n30\n35\n40\n45\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "i=10\nwhile i<20:\n i=i+1\nprint(i)\nprint(\"hello\")",
"execution_count": 128,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "20\nhello\n"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.8.3",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "bd0836d8883765f07689c25332b61fe3",
"data": {
"description": "basics_day01.ipynb",
"public": true
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/bd0836d8883765f07689c25332b61fe3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment