Skip to content

Commit e74e1d8

Browse files
committed
add about variables
0 parents  commit e74e1d8

File tree

2 files changed

+426
-0
lines changed

2 files changed

+426
-0
lines changed
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Naming things with Variables"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"> \"What should we gain by a definition, as it can only lead us to other undefined terms...\n",
15+
"\n",
16+
"> ...But ordinary language is all right.\" \n",
17+
"\n",
18+
"> Ludwig Wittgenstein"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"### Objectives"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"metadata": {},
31+
"source": [
32+
"### Declaring and Assigning Variables"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"metadata": {},
38+
"source": [
39+
"So far we have only worked with data. Strings, numbers, True and False. In this lesson, we lesson we assign them meaning. For example, this is a string from our Working with DataTypes Lab."
40+
]
41+
},
42+
{
43+
"cell_type": "code",
44+
"execution_count": 1,
45+
"metadata": {},
46+
"outputs": [
47+
{
48+
"data": {
49+
"text/plain": [
50+
"'art vandelay'"
51+
]
52+
},
53+
"execution_count": 1,
54+
"metadata": {},
55+
"output_type": "execute_result"
56+
}
57+
],
58+
"source": [
59+
"\"art vandelay\""
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {},
65+
"source": [
66+
"Now months later, if we see that string in some code, we may be confused as to where that code came from. Or when we start working with more data, it may become difficult to keep track of. Think of the data that we saw in our datatypes lab: `\"[email protected]\"`, `\"Ceo\"`, `\"7285553334\"`, `\"vandelay.com\"`. There's a lot to keep track of.\n",
67+
"\n",
68+
"So let's use a variable to indicate what each of these strings mean."
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 8,
74+
"metadata": {
75+
"collapsed": true
76+
},
77+
"outputs": [],
78+
"source": [
79+
"email = \"[email protected]\""
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"In programming terms, we say that the previous line declared a variable `email` and assigned it to the string `\"[email protected]\"`. To see that string again, we just need to type the text `email`.\n",
87+
"\n",
88+
"And to do this, we just wrote the plain text, or bare word `email`, used an equals sign to set that word equal to the string `\"[email protected]\"`.\n",
89+
"\n",
90+
"Now that we have done this, we just type the word `email` to see the string again. "
91+
]
92+
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": 9,
96+
"metadata": {},
97+
"outputs": [
98+
{
99+
"data": {
100+
"text/plain": [
101+
102+
]
103+
},
104+
"execution_count": 9,
105+
"metadata": {},
106+
"output_type": "execute_result"
107+
}
108+
],
109+
"source": [
110+
"email"
111+
]
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"Ok, let's do this with the website too."
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 10,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"data": {
127+
"text/plain": [
128+
"'vandelay.com'"
129+
]
130+
},
131+
"execution_count": 10,
132+
"metadata": {},
133+
"output_type": "execute_result"
134+
}
135+
],
136+
"source": [
137+
"website = \"vandelay.com\"\n",
138+
"website"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {},
144+
"source": [
145+
"** If there is no variable it blows up ** "
146+
]
147+
},
148+
{
149+
"cell_type": "markdown",
150+
"metadata": {},
151+
"source": [
152+
"So this is assigning and reading a variable. It will help us out out over time. Now when we want to see some information again, we can easily find out."
153+
]
154+
},
155+
{
156+
"cell_type": "code",
157+
"execution_count": 11,
158+
"metadata": {},
159+
"outputs": [
160+
{
161+
"data": {
162+
"text/plain": [
163+
164+
]
165+
},
166+
"execution_count": 11,
167+
"metadata": {},
168+
"output_type": "execute_result"
169+
}
170+
],
171+
"source": [
172+
"email"
173+
]
174+
},
175+
{
176+
"cell_type": "markdown",
177+
"metadata": {},
178+
"source": [
179+
"### Working with Abstraction"
180+
]
181+
},
182+
{
183+
"cell_type": "code",
184+
"execution_count": null,
185+
"metadata": {
186+
"collapsed": true
187+
},
188+
"outputs": [],
189+
"source": []
190+
}
191+
],
192+
"metadata": {
193+
"kernelspec": {
194+
"display_name": "Python 3",
195+
"language": "python",
196+
"name": "python3"
197+
},
198+
"language_info": {
199+
"codemirror_mode": {
200+
"name": "ipython",
201+
"version": 3
202+
},
203+
"file_extension": ".py",
204+
"mimetype": "text/x-python",
205+
"name": "python",
206+
"nbconvert_exporter": "python",
207+
"pygments_lexer": "ipython3",
208+
"version": "3.6.1"
209+
}
210+
},
211+
"nbformat": 4,
212+
"nbformat_minor": 2
213+
}

0 commit comments

Comments
 (0)