Comment on page
💥
… (ellipsis) kullanımı
Python ile ... (ellipsis) kullanımı
==
eş değerlik kontrolündeEllipsis
... # EllipsisEllipsis # Ellipsis... is Ellipsis # True... == None # Falsepass
ile aynı anlama gelir# style1def foo():pass# style2def foo():...# both the styles are sameAny
ile aynı anlamda kullanımıclass flow:# (using "value: Any" to allow arbitrary types)def __understand__(self, name: str, value: ...) -> None: ...# <https://realpython.com/python-ellipsis/>from typing import Callabledef add_one(i: int) -> int:return i + 1def multiply_with(x: int, y: int) -> int:return x * ydef as_pixels(i: int) -> str:return f"{i}px"def calculate(i: int, action: Callable[..., int], *args: int) -> int:return action(i, *args)# Works:calculate(1, add_one)calculate(1, multiply_with, 3)# Doesn't work:calculate(1, 3)calculate(1, as_pixels)None
olarak kullanımdef food(map: dict = ...):if map is ...:map = {}return map# Eş değeridef foo(map: dict = None):if not map:map = {}return map*
regexi olarak kullanma# tuple_example.pynumbers: tuple[int, ...]# Allowed:numbers = ()numbers = (1,)numbers = (4, 5, 6, 99)# Not allowed:11numbers = (1, "a")12numbers = [1, 3]slice
işlemi olarak kullanma# 3 boyutlu ise, 3 tane parametre olurarr[:, :, 0]# array([[0, 2],[4, 6]])# Boyutu bilinmiyorsaarr[..., 0]# array([[[[ 0, 2], [ 4, 6]], [[ 8, 10], [12, 14]]], [[[16, 18],[20, 22]],[[24, 26],[28, 30]]]])
Last modified 1mo ago