Skip to content

Commit 180633c

Browse files
committed
Fix Typos
1 parent 5afc032 commit 180633c

2 files changed

Lines changed: 33 additions & 25 deletions

File tree

README.md

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

244-
Note: Avoid `+` operator for string concatenation. Prefer string formatting.
244+
PS: 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,8 +352,8 @@ Evaluates to the integer value of the number of characters in a string:
352352
5
353353
```
354354

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

358358
```python
359359
>>> a = [1, 2, 3]
@@ -365,6 +365,8 @@ boolean evaluation:
365365

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

368+
Convert Between Data Types:
369+
368370
Integer to String or Float:
369371

370372
```python
@@ -668,7 +670,7 @@ You can even use a negative number for the step argument to make the for loop co
668670
### For else statement
669671

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

673675
```python
674676
>>> for i in [1, 2, 3, 4, 5]:
@@ -776,7 +778,7 @@ Hello!
776778
True
777779
```
778780

779-
Never compare to None with the `==` operator.
781+
PS: nevel compares to None with the `==` operator.
780782

781783
[*Return to the Top*](#python-cheatsheet)
782784

@@ -1513,7 +1515,7 @@ That is Carol\'s cat.
15131515

15141516
[*Return to the Top*](#python-cheatsheet)
15151517

1516-
Note: mostly used for regular expression definition (see `re` package).
1518+
PS: mostly used for regular expression definition (see `re` package)
15171519

15181520
### Multiline Strings with Triple Quotes
15191521

@@ -1559,6 +1561,7 @@ This generates the same string than before.
15591561

15601562
```python
15611563
>>> spam = 'Hello world!'
1564+
15621565
>>> spam[0]
15631566
'H'
15641567
```
@@ -1576,6 +1579,7 @@ This generates the same string than before.
15761579
Slicing:
15771580

15781581
```python
1582+
15791583
>>> spam[0:5]
15801584
'Hello'
15811585
```
@@ -1658,7 +1662,7 @@ True
16581662

16591663
### The upper(), lower(), isupper(), and islower() String Methods
16601664

1661-
upper() and lower():
1665+
`upper()` and `lower()`:
16621666

16631667
```python
16641668
>>> spam = 'Hello world!'
@@ -1883,6 +1887,8 @@ center():
18831887

18841888
### % operator
18851889

1890+
Note: For new code prefere using str.format over the `%` operator.
1891+
18861892
```python
18871893
>>> name = 'Pete'
18881894
>>> 'Hello %s' % name
@@ -1897,8 +1903,6 @@ We can use the `%x` format specifier to convert an int value to a string:
18971903
"I have 5 apples"
18981904
```
18991905

1900-
Note: For new code prefer using str.format over the `%` operator.
1901-
19021906
[*Return to the Top*](#python-cheatsheet)
19031907

19041908
### String Formatting (str.format)
@@ -2066,7 +2070,7 @@ The | character is called a pipe. You can use it anywhere you want to match one
20662070
'Tina Fey'
20672071
```
20682072

2069-
You can also use pipe to match one of several patterns as part of your regex:
2073+
You can also use the pipe to match one of several patterns as part of your regex:
20702074

20712075
```python
20722076
>>> bat_regex = re.compile(r'Bat(man|mobile|copter|bat)')
@@ -2561,12 +2565,12 @@ And all is good :)
25612565

25622566
### Absolute vs. Relative Paths
25632567

2564-
There are two ways to specify a file path:
2568+
There are two ways to specify a file path.
25652569

2566-
- An absolute path, which always begins with the root folder.
2567-
- A relative path, which is relative to the program’s current working directory.
2570+
- An absolute path, which always begins with the root folder
2571+
- A relative path, which is relative to the program’s current working directory
25682572

2569-
There are also the dot (.) and dot-dot (..) folders. These are not real folders but special names that can be used in a path. A single period (“dot”) for a folder name is shorthand for “this directory.” Two periods (“dot-dot”) means “the parent folder”.
2573+
There are also the dot (.) and dot-dot (..) folders. These are not real folders but special names that can be used in a path. A single period (“dot”) for a folder name is shorthand for “this directory.” Two periods (“dot-dot”) means “the parent folder.”
25702574

25712575
[*Return to the Top*](#python-cheatsheet)
25722576

@@ -2594,7 +2598,7 @@ True
25942598
False
25952599
```
25962600

2597-
*You can extract an absolute path with both `os.path` and `pathlib`*
2601+
You can extract an absolute path with both `os.path` and `pathlib`
25982602

25992603
Using `os.path` on \*nix:
26002604

@@ -2616,7 +2620,7 @@ print(Path('..').resolve())
26162620
/home
26172621
```
26182622

2619-
You can get a relative path from a starting path to another path:
2623+
You can get a relative path from a starting path to another path.
26202624

26212625
Using `os.path` on \*nix:
26222626

@@ -2638,6 +2642,8 @@ etc/passwd
26382642

26392643
### Checking Path Validity
26402644

2645+
Checking if a file/directory exists:
2646+
26412647
Using `os.path` on \*nix:
26422648

26432649
```python
@@ -2722,6 +2728,8 @@ False
27222728

27232729
### Finding File Sizes and Folder Contents
27242730

2731+
Getting a file's size in bytes:
2732+
27252733
Using `os.path` on Windows:
27262734

27272735
```python
@@ -2914,14 +2922,14 @@ The current folder is C:\delicious\walnut\waffles
29142922
FILE INSIDE C:\delicious\walnut\waffles: butter.txt
29152923
```
29162924

2925+
[*Return to the Top*](#python-cheatsheet)
2926+
29172927
`pathlib` provides a lot more functionality than the ones listed above,
29182928
like getting file name, getting file extension, reading/writing a file without
29192929
manually opening it, etc. Check out the
29202930
[official documentation](https://docs.python.org/3/library/pathlib.html)
29212931
if you want to know more!
29222932

2923-
[*Return to the Top*](#python-cheatsheet)
2924-
29252933
## Reading and Writing Files
29262934

29272935
### The File Reading/Writing Process
@@ -3168,9 +3176,9 @@ conf1 = anyconfig.load("/path/to/foo/conf.d/a.yml")
31683176

31693177
Exceptions are raised with a raise statement. In code, a raise statement consists of the following:
31703178

3171-
- The raise keyword.
3172-
- A call to the Exception() function.
3173-
- A string with a helpful error message passed to the Exception() function.
3179+
- The raise keyword
3180+
- A call to the Exception() function
3181+
- A string with a helpful error message passed to the Exception() function
31743182

31753183
```python
31763184
>>> raise Exception('This is the error message.')
@@ -3444,7 +3452,7 @@ Like regular nested functions, lambdas also work as lexical closures:
34443452
9
34453453
```
34463454

3447-
Note: lambda can only evaluate an expression, like a single line of code.
3455+
PS: lambda can only evaluate an expression, like a single line of code.
34483456

34493457
[*Return to the Top*](#python-cheatsheet)
34503458

python_cheat_sheet.pdf

9.07 KB
Binary file not shown.

0 commit comments

Comments
 (0)