@@ -54,33 +54,22 @@ NameError: name 'thingy' is not defined
54
54
>> >
55
55
```
56
56
57
- Variables are simple to understand, but there's a few details that we
57
+ Variables are simple to understand, but there are a few details that we
58
58
need to keep in mind:
59
59
60
60
- Variables always point to a value, ** they never point to other
61
- variables** . That's why the arrows in our diagrams always go left
62
- to right.
61
+ variables** . That's why the arrows in our diagrams always go left
62
+ to right.
63
63
- Multiple variables can point to the same value, but one variable
64
- cannot point to multiple values.
64
+ cannot point to multiple values.
65
65
- The values that variables point to can point to other values also.
66
- We'll learn more about that when we'll talk about
67
- [ lists] ( lists-and-tuples.md ) .
66
+ We'll learn more about that when we'll talk about
67
+ [ lists] ( lists-and-tuples.md ) .
68
68
69
69
Variables are an important part of most programming languages, and they
70
70
allow programmers to write much larger programs than they could write
71
71
without variables.
72
72
73
- Variable names can be multiple characters long. They can contain
74
- uppercase characters, numbers and some other characters, but most of the
75
- time we should use simple, lowercase variable names. You can also use
76
- underscores.
77
-
78
- ``` python
79
- >> > magic_number = 123
80
- >> > greeting = " Hello World!"
81
- >> >
82
- ```
83
-
84
73
Variable names are case-sensitive, like many other things in Python.
85
74
86
75
``` python
@@ -96,7 +85,7 @@ Variable names are case-sensitive, like many other things in Python.
96
85
>> >
97
86
```
98
87
99
- Python also has some words that cannot be used as variable names
88
+ There are also words that cannot be used as variable names
100
89
because they have a special meaning. They are called ** keywords** , and
101
90
we can run ` help('keywords') ` to see the full list if we want to.
102
91
We'll learn to use most of them later in this tutorial. Trying to use a
@@ -158,6 +147,36 @@ variable called hello and then type hello:
158
147
>> >
159
148
```
160
149
150
+ ## Good and bad variable names
151
+
152
+ Variable names can be multiple characters long. They can contain
153
+ uppercase characters, numbers and some other characters, but most of the
154
+ time we should use simple, lowercase variable names. We can also use
155
+ underscores. For example, these variable names are good:
156
+
157
+ ``` python
158
+ >> > magic_number = 123
159
+ >> > greeting = " Hello World!"
160
+ >> >
161
+ ```
162
+
163
+ Don't use variable names like this, ** these variables are _ bad_ ** :
164
+
165
+ ``` python
166
+ >> > magicNumber = 3.14
167
+ >> > Greeting = " Hello there!"
168
+ >> > x = " Hello again!"
169
+ >> >
170
+ ```
171
+
172
+ All of these variables work just fine, but other Python programmers
173
+ don't want you to use them. Most Python code doesn't use variable names
174
+ that contain UpperCase letters like ` magicNumber ` and ` Greeting ` , so
175
+ other people reading your code will think it looks weird if you use
176
+ them. The problem with ` x ` is that it's too short, and people have no
177
+ idea what it is. Remember that mathematicians like figuring out what x
178
+ is, but programmers hate that.
179
+
161
180
## Booleans
162
181
163
182
There are two Boolean values, True and False. In Python, and in many
224
243
225
244
Another confusing thing is that if we do something weird to None we get
226
245
error messages that talk about NoneType object. The NoneType object they
227
- are talking about is always None.
246
+ are talking about is always None. We'll learn more about what attributes
247
+ and calling are later.
228
248
229
249
``` python
230
250
>> > None .hello # None has no attribute 'hello'
@@ -240,16 +260,15 @@ TypeError: 'NoneType' object is not callable
240
260
241
261
## Other comparing operators
242
262
243
- So far we've used ` == ` , but there are other operators also. At this
244
- point, this list probably looks awfully long, but it's actually pretty
245
- easy to learn.
263
+ So far we've used ` == ` , but there are other operators also. This list
264
+ probably looks awfully long, but it's actually quite easy to learn.
246
265
247
266
| Usage | Description | True examples |
248
267
| -----------| -----------------------------------| -----------------------|
249
268
| ` a == b ` | a is equal to b | ` 1 == 1 ` |
250
269
| ` a != b ` | a is not equal to b | ` 1 != 2 ` |
251
- | ` a > b ` | a is greater than b | ` 2 > 1 ` |
252
- | ` a >= b ` | a is greater than or equal to b | ` 2 >= 1 ` , ` 1 >= 1 ` |
270
+ | ` a > b ` | a is bigger than b | ` 2 > 1 ` |
271
+ | ` a >= b ` | a is bigger than or equal to b | ` 2 >= 1 ` , ` 1 >= 1 ` |
253
272
| ` a < b ` | a is less than b | ` 1 < 2 ` |
254
273
| ` a <= b ` | a is less than or equal to b | ` 1 <= 2 ` , ` 1 <= 1 ` |
255
274
@@ -261,15 +280,24 @@ b are Booleans.
261
280
| ` a and b ` | a is True and b is True | ` 1 == 1 and 2 == 2 ` |
262
281
| ` a or b ` | a is True, b is True or they're both True | ` False or 1 == 1 ` , ` True or True ` |
263
282
264
- Another way to combine operations is chaining. For example, ` a < b < c `
265
- does the same thing as ` a < b and b < c ` .
266
-
267
283
` not ` can be used for negations. If ` value ` is True, ` not value ` is
268
284
False, and if ` value ` is False, ` not value ` is True.
269
285
270
286
There's also ` is ` , but don't use it instead of ` == ` unless you know
271
287
what you are doing. We'll learn more about it later.
272
288
289
+ ## Summary
290
+
291
+ - Variables have a name and a value. We can create or change variables
292
+ with ` name = value ` .
293
+ - ` thing += stuff ` does the same thing as ` thing = thing + stuff ` .
294
+ - Use lowercase variable names and remember that programmers hate
295
+ figuring out what x is.
296
+ - ` = ` means assigning and ` == ` means comparing.
297
+ - True and False are Booleans. Comparing values results in a Boolean.
298
+ - None is a value that we'll find useful later. When error messages say
299
+ ` NoneType object ` they mean None.
300
+
273
301
***
274
302
275
303
If you have trouble with this tutorial please [ tell me about
0 commit comments