網站首頁 編程語言 正文
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解釋器中的默認輔助提示符(default secondary prompt):
3. 它用于訪問和切片(accessing and slicing)多維數組/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
# 當函數的參數類型允許為Any
def inject(get_next_item: Callable[..., str]) -> None:
...
def foo(x: ...) -> None:
...
# 當函數的返回類型為Any
class flow:
def __understand__(self, name: str, value: ...) -> None:
...
5. 它可用作函數內部的pass語句:
# 5. used as Pass Statement inside Functions
# foo1 and foo2 styles are same
def foo1():
pass
def foo2():
...
6. 它可用作默認參數值:
# 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
相關推薦
- 2022-07-06 R語言可視化開發forestplot根據分組設置不同顏色_R語言
- 2022-09-10 Go語言中使用urfave/cli命令行框架_Golang
- 2022-07-12 springboot整合jasypt加密yml配置文件
- 2022-08-15 接口狀態與策略路由表
- 2022-10-30 淺析pytest?鉤子函數?之初始鉤子和引導鉤子_python
- 2022-06-09 使用Ajax實現進度條的繪制_AJAX相關
- 2022-04-06 React中使用react-player?播放視頻或直播的方法_React
- 2022-07-10 linux基礎命令運用
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支