@@ -131,8 +131,8 @@ greet("Carol", times=3) # Hello, Carol! (×3)
131131### Type Annotations
132132
133133``` python
134- def add (x : int , y : int ) -> int :
135- return x + y
134+ def add (x : int , b : int ) -> int :
135+ return x + b
136136
137137def process (items : list , limit : int = 10 ) -> dict :
138138 return {i: items[i] for i in range (min (limit, len (items)))}
@@ -226,8 +226,8 @@ def log_calls(func):
226226 return wrapper
227227
228228@log_calls
229- def add (x , y ):
230- return x + y
229+ def add (x , b ):
230+ return x + b
231231
232232add(3 , 4 )
233233# Calling add
@@ -265,7 +265,7 @@ def my_decorator(func):
265265
266266``` python
267267let square = lambda x : x ** 2
268- let add = lambda x , y : x + y
268+ let add = lambda x , b : x + b
269269let clamp = lambda val , lo , hi : max (lo, min (hi, val))
270270
271271print (square(5 )) # 25
@@ -481,22 +481,22 @@ print(temp.fahrenheit) # 32.0
481481class Vector :
482482 def __init__ (self , x , y_val ):
483483 self .x = x
484- self .y = y_val
484+ self .y_val = y_val
485485
486486 def __add__ (self , other ):
487- return Vector(self .x + other.x, self .y + other.y )
487+ return Vector(self .x + other.x, self .y_val + other.y_val )
488488
489489 def __mul__ (self , scalar ):
490- return Vector(self .x * scalar, self .y * scalar)
490+ return Vector(self .x * scalar, self .y_val * scalar)
491491
492492 def __len__ (self ):
493493 return 2
494494
495495 def __repr__ (self ):
496- return f " Vector( { self .x} , { self .y } ) "
496+ return f " Vector( { self .x} , { self .y_val } ) "
497497
498498 def __eq__ (self , other ):
499- return self .x == other.x and self .y == other.y
499+ return self .x == other.x and self .y_val == other.y_val
500500
501501
502502let v1 = Vector(1 , 2 )
@@ -517,11 +517,11 @@ from dataclasses import dataclass, field
517517@dataclass
518518class Point :
519519 x: float
520- y : float
520+ y_coord : float
521521 label: str = " "
522522
523523 def distance_from_origin (self ):
524- return (self .x** 2 + self .y ** 2 ) ** 0.5
524+ return (self .x** 2 + self .y_coord ** 2 ) ** 0.5
525525
526526
527527@dataclass
@@ -534,7 +534,7 @@ class Polygon:
534534
535535
536536let p = Point(3.0 , 4.0 , " A" )
537- print (p) # Point(x=3.0, y =4.0, label='A')
537+ print (p) # Point(x=3.0, y_coord =4.0, label='A')
538538print (p.distance_from_origin()) # 5.0
539539```
540540
0 commit comments