UNCLASSIFIED

Skip to content
Snippets Groups Projects
Commit 680d4d3b authored by kmc-home's avatar kmc-home
Browse files

update site

parent 79293cc2
No related merge requests found
Pipeline #120210 passed with stage
in 11 seconds
......@@ -6,4 +6,5 @@
.fluent_python_notes.md
.blocks1-4-notes.md
.example
.py1b2-full.md
\ No newline at end of file
.py1b2-full.md
.vscode
\ No newline at end of file
......@@ -67,12 +67,15 @@ print(text[-11:]) # "Programming" same as text[7:]
```
The slice notation works because strings implement the sequence protocol, which includes:
- `__len__` - Returns length of sequence
- `__getitem__` - Handles both index and slice access
- `__iter__` - Makes the object iterable
!!! Note "Slice Objects"
Slices are actually objects in Python. When you use slice notation, Python creates a `slice` object:
```python
# These are equivalent:
text[1:5]
......@@ -268,7 +271,9 @@ hash_value = hashlib.sha256(message).hexdigest()
```
!!! Note "When to Use Bytes"
You'll work with bytes directly when:
**You'll work with bytes directly when:**
- Reading/writing binary files (images, executables)
- Implementing network protocols
- Processing fixed-width data formats
......@@ -277,7 +282,9 @@ hash_value = hashlib.sha256(message).hexdigest()
- Interfacing with C libraries or system calls
!!! Warning "Encoding Errors"
When working with encodings, you might encounter errors. Python provides several error handlers:
```python
# Different error handling strategies
text = "Hello, 世界"
......@@ -320,7 +327,8 @@ with open('output.txt', 'w') as f:
```
!!! Note "`with`"
We'll cover the `with` statement in more detail in future lessons. For now, just know that it's a convience feature that ensures resources are released when they are no longer needed.
We'll cover the `with` statement in more detail in future lessons. For now, just know that it's a convenience feature that ensures resources are released when they are no longer needed.
### input()
......
temp.py 0 → 100644
# name = "Kevin"
# print(id(name))
# name = name.replace("v", "!")
# print(name)
# print(id(name))
my_string = "Kevin"
print(my_string)
print(id(my_string))
my_string = "Kevin" + "!"
print(my_string)
print(id(my_string))
print()
my_list = [1, 2, 3]
print(my_list)
print(id(my_list))
my_list.append(4)
print(my_list)
print(id(my_list))
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment