Skip to content

Commit 41f9ecb

Browse files
Manual review of builtin functions: hex-int
1 parent 723f24e commit 41f9ecb

5 files changed

Lines changed: 0 additions & 546 deletions

File tree

docs/builtins/bin.md

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,6 @@ value = int("1010", 2) # Also O(log n)
114114
assert value == 10
115115
```
116116

117-
## Comparison with Alternatives
118-
119-
### bin() vs format()
120-
121-
```python
122-
# bin() - returns string with '0b' prefix
123-
bin(255) # '0b11111111'
124-
125-
# format() - more flexible
126-
format(255, 'b') # '11111111' (no prefix)
127-
format(255, '#b') # '0b11111111' (with prefix)
128-
129-
# Performance - both O(log n), similar speed
130-
```
131-
132-
### bin() vs bit_length()
133-
134-
```python
135-
# bin() - string representation, O(log n)
136-
s = bin(255) # '0b11111111'
137-
138-
# bit_length() - O(1) operation
139-
bits = (255).bit_length() # 8
140-
141-
# Use bit_length() for count, bin() for display
142-
```
143-
144117
## Bit Manipulation Operations
145118

146119
```python
@@ -259,35 +232,6 @@ my_set &= ~(1 << 3)
259232
print(bin(my_set)) # '0b100000'
260233
```
261234

262-
## Special Cases
263-
264-
### Zero
265-
266-
```python
267-
# O(1)
268-
bin(0) # '0b0'
269-
```
270-
271-
### Powers of Two
272-
273-
```python
274-
# O(log n) - shows single bit set
275-
bin(1) # '0b1'
276-
bin(2) # '0b10'
277-
bin(4) # '0b100'
278-
bin(8) # '0b1000'
279-
bin(2**10) # Single '1' followed by zeros
280-
```
281-
282-
### All Ones
283-
284-
```python
285-
# O(log n) - all bits set
286-
bin(0xFF) # '0b11111111' (255)
287-
bin(0xFFFF) # 16 ones
288-
bin((1 << 32) - 1) # 32 ones
289-
```
290-
291235
## Best Practices
292236

293237
**Do**:

docs/builtins/breakpoint.md

Lines changed: 0 additions & 241 deletions
Original file line numberDiff line numberDiff line change
@@ -9,247 +9,6 @@ The `breakpoint()` function drops into the Python debugger (pdb by default) for
99
| `breakpoint()` | O(1) | O(1) | Pauses execution |
1010
| Debugger session | O(n) | O(n) | n = time spent debugging |
1111

12-
## Basic Usage
13-
14-
### Simple Breakpoint
15-
16-
```python
17-
def process_data(data):
18-
print(f"Input: {data}")
19-
breakpoint() # Drop into debugger
20-
print(f"Processed: {data.upper()}")
21-
22-
process_data("hello")
23-
24-
# At debugger:
25-
# (Pdb) data
26-
# 'hello'
27-
# (Pdb) continue
28-
```
29-
30-
### Conditional Breakpoint
31-
32-
```python
33-
def find_error(items):
34-
for i, item in enumerate(items):
35-
if item < 0:
36-
print(f"Found negative at index {i}")
37-
breakpoint() # Debug only on error
38-
print(item)
39-
40-
find_error([1, 2, -3, 4])
41-
```
42-
43-
### Debugging Inside Function
44-
45-
```python
46-
def calculate(a, b, c):
47-
result = a + b
48-
breakpoint() # Inspect variables
49-
result *= c
50-
return result
51-
52-
value = calculate(1, 2, 3)
53-
54-
# At debugger:
55-
# (Pdb) result
56-
# 3
57-
# (Pdb) a, b, c
58-
# (1, 2, 3)
59-
# (Pdb) continue
60-
```
61-
62-
## Debugger Commands
63-
64-
### Common PDB Commands
65-
66-
```python
67-
value = 42
68-
breakpoint()
69-
70-
# Commands at (Pdb) prompt:
71-
# l (list) - Show source code
72-
# n (next) - Execute next line
73-
# s (step) - Step into function
74-
# c (continue) - Resume execution
75-
# u (up) - Go up stack frame
76-
# d (down) - Go down stack frame
77-
# p variable - Print variable
78-
# pp variable - Pretty print
79-
# h (help) - Show help
80-
# q (quit) - Exit debugger
81-
```
82-
83-
### Example Debugging Session
84-
85-
```python
86-
def buggy_function(x, y):
87-
result = x + y
88-
breakpoint() # Stop here
89-
result *= 2
90-
return result
91-
92-
buggy_function(10, 20)
93-
94-
# Session output:
95-
# > /path/to/file.py:4in buggy_function()
96-
# -> result *= 2
97-
# (Pdb) x
98-
# 10
99-
# (Pdb) y
100-
# 20
101-
# (Pdb) result
102-
# 30
103-
# (Pdb) continue
104-
```
105-
106-
## Custom Debugger
107-
108-
### Using Different Debugger
109-
110-
```python
111-
import pdb
112-
113-
# Use custom debugger instead of default pdb
114-
def custom_debugger():
115-
debugger = pdb.Pdb()
116-
debugger.set_trace()
117-
118-
custom_debugger()
119-
```
120-
121-
### Disabling Breakpoints
122-
123-
```python
124-
import sys
125-
126-
# Disable all breakpoints
127-
def no_breakpoint(*args, **kwargs):
128-
pass
129-
130-
# PYTHONBREAKPOINT=0 environment variable also disables
131-
132-
# Or set in code
133-
sys.__breakpointhook__ = no_breakpoint
134-
breakpoint() # Does nothing
135-
```
136-
137-
## Environment Control
138-
139-
### Disable Via Environment
140-
141-
```bash
142-
# Disable all breakpoints
143-
export PYTHONBREAKPOINT=0
144-
python script.py
145-
146-
# Use custom debugger
147-
export PYTHONBREAKPOINT=mymodule.debugger
148-
python script.py
149-
```
150-
151-
### Programmatic Control
152-
153-
```python
154-
import sys
155-
156-
# Custom breakpoint handler
157-
def my_breakpoint(*args, **kwargs):
158-
print("Breakpoint hit!")
159-
# Custom logic
160-
import pdb
161-
pdb.set_trace(*args, **kwargs)
162-
163-
sys.breakpointhook = my_breakpoint
164-
165-
breakpoint() # Uses custom handler
166-
```
167-
168-
## Best Practices
169-
170-
```python
171-
# ✅ DO: Use for development debugging
172-
def complex_calculation(data):
173-
processed = preprocess(data)
174-
breakpoint() # Inspect intermediate result
175-
return postprocess(processed)
176-
177-
# ❌ DON'T: Leave breakpoints in production
178-
# Use logging instead for production debugging
179-
180-
import logging
181-
logging.debug(f"Value: {x}")
182-
183-
# ✅ DO: Remove before committing
184-
# Use version control to track breakpoints
185-
186-
# ✅ DO: Use conditional breakpoints
187-
if condition:
188-
breakpoint()
189-
190-
# ✅ DO: Use logging for production
191-
try:
192-
operation()
193-
except Exception as e:
194-
logging.exception("Operation failed")
195-
```
196-
197-
## Debugging Techniques
198-
199-
### Inspect Call Stack
200-
201-
```python
202-
def level3():
203-
breakpoint()
204-
205-
def level2():
206-
level3()
207-
208-
def level1():
209-
level2()
210-
211-
level1()
212-
213-
# At breakpoint:
214-
# (Pdb) bt # Backtrace - show call stack
215-
# > /path/file.py:2in level3()
216-
# > /path/file.py:5in level2()
217-
# > /path/file.py:8in level1()
218-
# > /path/file.py:11in <module>()
219-
```
220-
221-
### Watch Variables
222-
223-
```python
224-
def process_list(items):
225-
total = 0
226-
for i, item in enumerate(items):
227-
total += item
228-
if total > 10:
229-
breakpoint() # When threshold reached
230-
# (Pdb) total
231-
# (Pdb) i, item
232-
# (Pdb) pp items
233-
234-
process_list([1, 2, 3, 4, 5, 6])
235-
```
236-
237-
### Execute Code in Debugger
238-
239-
```python
240-
def debug_example():
241-
x = 10
242-
y = 20
243-
breakpoint()
244-
# At (Pdb), you can:
245-
# (Pdb) z = x + y
246-
# (Pdb) z
247-
# 30
248-
# (Pdb) import json
249-
# (Pdb) json.dumps({'x': x})
250-
251-
debug_example()
252-
```
25312

25413
## Related Modules
25514

docs/builtins/hex.md

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -112,52 +112,6 @@ print(hex(id(obj2)))
112112
# Different addresses shown in hex
113113
```
114114

115-
## Comparison with Alternatives
116-
117-
### hex() vs format()
118-
119-
```python
120-
# hex() - returns string with '0x' prefix
121-
hex(255) # '0xff'
122-
123-
# format() - more flexible
124-
format(255, 'x') # 'ff' (no prefix)
125-
format(255, 'X') # 'FF' (uppercase, no prefix)
126-
format(255, '#x') # '0xff' (with prefix)
127-
128-
# Performance - both O(log n), format slightly faster
129-
```
130-
131-
### hex() vs bin() vs oct()
132-
133-
```python
134-
# All O(log n) but different bases
135-
hex(255) # '0xff' (base 16)
136-
bin(255) # '0b11111111' (base 2)
137-
oct(255) # '0o377' (base 8)
138-
139-
# Which base?
140-
# hex - most compact, good for colors/addresses
141-
# bin - for bit manipulation
142-
# oct - rare, legacy use
143-
```
144-
145-
## Builtin Integer Methods
146-
147-
```python
148-
# to_bytes() - O(log n) alternative
149-
x = 255
150-
hex_bytes = x.to_bytes(2, 'big')
151-
# b'\x00\xff'
152-
153-
# bit_length() - O(1) related operation
154-
x = 255
155-
bits = x.bit_length() # 8
156-
hex(x) # '0xff' - 2 digits = 8 bits
157-
158-
# Relationship: hex digits ≈ bit_length() / 4
159-
```
160-
161115
## Bidirectional Conversion
162116

163117
```python
@@ -199,24 +153,6 @@ hex_str = ''.join(hex(v)[2:] for v in values)
199153
# 'a141e28' - concatenated hex values
200154
```
201155

202-
## Special Cases
203-
204-
### Zero
205-
206-
```python
207-
# O(1)
208-
hex(0) # '0x0'
209-
```
210-
211-
### Powers of Two
212-
213-
```python
214-
# O(log n) - still efficient even for powers
215-
hex(2**10) # '0x400'
216-
hex(2**20) # '0x100000'
217-
hex(2**100) # Very large hex number, still O(log 2**100)
218-
```
219-
220156
## Common Use Cases
221157

222158
### Debug Output

0 commit comments

Comments
 (0)