網(wǎng)站首頁 編程語言 正文
1. 省略號(...)是一個Python對象,叫Ellipsis,它沒有方法,是一個單例對象(singleton object):
# 1. ...是一個python對象,叫Ellipsis
print(type(...)) # output: <class 'ellipsis'>
print(...) # output: Ellipsis
print(Ellipsis) # output: Ellipsis
print(bool(...)) # output: True
2. 它可用作Python解釋器中的默認(rèn)輔助提示符(default secondary prompt):
3. 它用于訪問和切片(accessing and slicing)多維數(shù)組/NumPy索引,注:不能在一個切片中有多個省略號
# 3. slice: we can not have multiple ellipsis in a single slicing
array = np.random.rand(2, 4) # a 2-dimensional matrix of order 2*4(rows*cols)
print(array); print(array[...]); print(array[Ellipsis]) # they are all equivalent
print(array[..., 0]); print(array[:,0]); print(array[Ellipsis, 0]) # they are all equivalent
print(array[0, ...])
4. 它可用在類型提示中(in type hinting):
# 4. type hints
# 當(dāng)函數(shù)的參數(shù)類型允許為Any
def inject(get_next_item: Callable[..., str]) -> None:
...
def foo(x: ...) -> None:
...
# 當(dāng)函數(shù)的返回類型為Any
class flow:
def __understand__(self, name: str, value: ...) -> None:
...
5. 它可用作函數(shù)內(nèi)部的pass語句:
# 5. used as Pass Statement inside Functions
# foo1 and foo2 styles are same
def foo1():
pass
def foo2():
...
6. 它可用作默認(rèn)參數(shù)值:
# 6. used as a default argument value
def foo3(x = ...):
return x
def foo4(x = None):
return x
print("foo3:", foo3) # output: foo3: <function foo3 at 0x7f4e7ffcf5e0>
print("foo4:", foo4) # output: foo4: <function foo4 at 0x7f4e7ffcf550>
GitHub:https://github.com/fengbingchun/Python_Test
原文鏈接:https://blog.csdn.net/fengbingchun/article/details/125284883
相關(guān)推薦
- 2023-05-06 react中定義變量并使用方式_React
- 2022-11-21 c/c++單例模式類的混合編譯案例詳解_C 語言
- 2023-02-27 一文搞懂Golang?值傳遞還是引用傳遞_Golang
- 2022-06-18 android實現(xiàn)可拖動的浮動view_Android
- 2022-08-10 詳細(xì)講解Swift中的類型占位符_Swift
- 2022-11-15 Python函數(shù)式編程之返回函數(shù)實例詳解_python
- 2022-10-02 SQL堆疊注入簡介_MsSql
- 2022-07-06 ?ASP.NET?Core?模型驗證過濾器的兩種實現(xiàn)方法_實用技巧
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支