Skip to content

Commit 2f70757

Browse files
committed
Minor changes.
1 parent 589a4b1 commit 2f70757

2 files changed

Lines changed: 16 additions & 19 deletions

File tree

README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ String concatenation:
241241
'AliceBob'
242242
```
243243

244-
PS: Avoid `+` operator for string concatenation. Prefer string formatting.
244+
Note: Avoid `+` operator for string concatenation. Prefer string formatting.
245245

246246
String Replication:
247247

@@ -259,7 +259,7 @@ You can name a variable anything as long as it obeys the following three rules:
259259
1. It can be only one word.
260260
1. It can use only letters, numbers, and the underscore (`_`) character.
261261
1. It can’t begin with a number.
262-
1. Variable name starting with an underscore (`_`) are considered as "unuseful`
262+
1. Variable name starting with an underscore (`_`) are considered as "unuseful`.
263263

264264
Example:
265265

@@ -292,13 +292,13 @@ Multiline comment:
292292
# multiline comment
293293
```
294294

295-
Code with a comment
295+
Code with a comment:
296296

297297
```python
298298
a = 1 # initialization
299299
```
300300

301-
Please note the two spaces in front of the comment
301+
Please note the two spaces in front of the comment.
302302

303303
Function docstring:
304304

@@ -352,7 +352,7 @@ Evaluates to the integer value of the number of characters in a string:
352352
5
353353
```
354354

355-
PS: test of emptiness of strings, lists, dictionary, etc, should **not** use len, but prefer direct
355+
Note: test of emptiness of strings, lists, dictionary, etc, should **not** use len, but prefer direct
356356
boolean evaluation.
357357

358358
```python
@@ -365,8 +365,6 @@ boolean evaluation.
365365

366366
### The str(), int(), and float() Functions
367367

368-
Convert Between Data Types:
369-
370368
Integer to String or Float:
371369

372370
```python
@@ -411,7 +409,7 @@ Float to Integer:
411409
| `<=` | Less than or Equal to |
412410
| `>=` | Greater than or Equal to |
413411

414-
These operators evaluate to True or False depending on the values you give them:
412+
These operators evaluate to True or False depending on the values you give them.
415413

416414
Examples:
417415

@@ -596,7 +594,7 @@ while spam < 5:
596594

597595
### break Statements
598596

599-
If the execution reaches a break statement, it immediately exits the while loop’s clause.
597+
If the execution reaches a break statement, it immediately exits the while loop’s clause:
600598

601599
```python
602600
while True:
@@ -670,7 +668,7 @@ You can even use a negative number for the step argument to make the for loop co
670668
### For else statement
671669

672670
This allows to specify a statement to execute in case of the full loop has been executed. Only
673-
useful when a `break` condition can occur in the loop
671+
useful when a `break` condition can occur in the loop:
674672

675673
```python
676674
>>> for i in [1, 2, 3, 4, 5]:
@@ -778,7 +776,7 @@ Hello!
778776
True
779777
```
780778

781-
PS: never compare to `None` with the `==` operator. Always use `is`.
779+
Note: never compare to `None` with the `==` operator. Always use `is`.
782780

783781
[*Return to the Top*](#python-cheatsheet)
784782

@@ -986,7 +984,6 @@ None
986984

987985
```python
988986
>>> spam = ['cat', 'bat', 'rat', 'elephant']
989-
990987
>>> spam[1] = 'aardvark'
991988

992989
>>> spam
@@ -1285,7 +1282,7 @@ myCat = {'size': 'fat', 'color': 'gray', 'disposition': 'loud'}
12851282

12861283
### The keys(), values(), and items() Methods
12871284

1288-
**values():**
1285+
values():
12891286

12901287
```python
12911288
>>> spam = {'color': 'red', 'age': 42}
@@ -1295,7 +1292,7 @@ red
12951292
42
12961293
```
12971294

1298-
**keys():**
1295+
keys():
12991296

13001297
```python
13011298
>>> for k in spam.keys():
@@ -1304,7 +1301,7 @@ color
13041301
age
13051302
```
13061303

1307-
**items():**
1304+
items():
13081305

13091306
```python
13101307
>>> for i in spam.items():
@@ -1516,7 +1513,7 @@ That is Carol\'s cat.
15161513

15171514
[*Return to the Top*](#python-cheatsheet)
15181515

1519-
PS: mostly used for regular expression definition (see `re` package)
1516+
Note: mostly used for regular expression definition (see `re` package)
15201517

15211518
### Multiline Strings with Triple Quotes
15221519

@@ -1888,8 +1885,6 @@ center():
18881885

18891886
### % operator
18901887

1891-
Note: For new code prefere using str.format over the `%` operator.
1892-
18931888
```python
18941889
>>> name = 'Pete'
18951890
>>> 'Hello %s' % name
@@ -1904,6 +1899,8 @@ We can use the `%x` format specifier to convert an int value to a string:
19041899
"I have 5 apples"
19051900
```
19061901

1902+
Note: For new code prefere using str.format over the `%` operator.
1903+
19071904
[*Return to the Top*](#python-cheatsheet)
19081905

19091906
### String Formatting (str.format)
@@ -3453,7 +3450,7 @@ Like regular nested functions, lambdas also work as lexical closures:
34533450
9
34543451
```
34553452

3456-
PS: lambda can only evaluate an expression, like a single line of code.
3453+
Note: lambda can only evaluate an expression, like a single line of code.
34573454

34583455
[*Return to the Top*](#python-cheatsheet)
34593456

python_cheat_sheet.pdf

-8.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)