You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/python_advanced_features.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -459,7 +459,7 @@ Overall, `*args` and `**kargs` are used when *defining a function*; they enable
459
459
460
460
The difference is that functions with `*args` will be able to take *positional arguments* with an arbitrary size, while `**kargs` will allow functions to take arbitrarily many *keyword arguments*.
461
461
462
-
## Type Hints
462
+
## Type hints
463
463
464
464
```{index} single: Python; Type Hints
465
465
```
@@ -476,7 +476,7 @@ Type hints were introduced in Python 3.5 and have become increasingly common in
476
476
Type hints are **ignored by the Python interpreter at runtime** --- they do not affect how your code executes. They are purely informational and serve as documentation for humans and tools.
477
477
```
478
478
479
-
### Basic Syntax
479
+
### Basic syntax
480
480
481
481
Type hints use the colon `:` to annotate variables and parameters, and the arrow `->` to annotate return types.
482
482
@@ -503,7 +503,7 @@ y: float = 3.14
503
503
name: str = 'Python'
504
504
```
505
505
506
-
### Common Types
506
+
### Common types
507
507
508
508
The most frequently used type hints are the built-in types:
An important point for new Python programmers: type hints are **not enforced** at runtime.
529
529
@@ -539,7 +539,7 @@ add('foo', 'bar')
539
539
540
540
This is a key difference from statically typed languages like C or Java, where mismatched types cause compilation errors.
541
541
542
-
### Why Use Type Hints?
542
+
### Why use type hints?
543
543
544
544
If Python ignores them, why bother?
545
545
@@ -548,7 +548,7 @@ If Python ignores them, why bother?
548
548
3.**Error checking**: Tools like [mypy](https://mypy.readthedocs.io/) and [pyrefly](https://pyrefly.org/) analyze type hints to catch bugs *before* you run your code.
549
549
4.**LLM-generated code**: Large language models frequently produce code with type hints, so understanding the syntax helps you read and use their output.
550
550
551
-
### Type Hints in Scientific Python
551
+
### Type hints in scientific Python
552
552
553
553
Type hints connect to the {doc}`need for speed <need_for_speed>` discussion:
0 commit comments