Error in user YAML: (<unknown>): found a tab character that violate indentation while scanning a plain scalar at line 3 column 3
---
- oeasy Python 0252
- 这是 oeasy 系统化 Python 教程,从基础一步步讲,扎实、完整、不跳步。愿意花时间学,就能真正学会。
- 本教程同步发布在:
- 个人网站: `https://oeasy.org`
- 蓝桥云课: `https://www.lanqiao.cn/courses/3584`
- GitHub: `https://github.com/overmind1980/oeasy-python-tutorial`
- Gitee: `https://gitee.com/overmind1980/oeasypython`
---- 上次研究了形(formal)参(parameter)的分类
- 分三种
- 纯位置形参
- 纯关键字形参
- 既可位置又可关键字形参
- 我们用到的都是第三种
- 真的可以有纯位置的形参么?
- /之前的是纯位置的
- /、*之间的是两可的(位置、关键字都可以)
- *之后的是纯关键字的
- 结果
- 3 个参数
- 1 个 positiononly
- 2 个 既可以position也可以keyword
- 如果我要用keyword形式给sub呢?
import sys
def sentence(sub: str="I",\
/,\
pre: str = "love",\
obj: str = "you"):
"""
a sentence is composed by 3 parts,
sub is abbreviation as subject
pre is abbreviation as predicate
obj is abbreviation as object
"""
frame = sys._getframe()
code = frame.f_code
print("co_argcount:",code.co_argcount)
print("co_posonlyargcount:",code.co_posonlyargcount)
print("co_kwonlyargcount:",code.co_kwonlyargcount)
print(sub, pre, obj)
sentence(sub="oeasy")
- sub声明了是纯position
- 不能用keyword来调用他
- 后面都是两可得
- 既可以是position
- 也可以是keyword
- 不only
- 我们这次研究了纯位置(position)参数(parameter)
- 纯位置参数在/之前
- 纯位置参数只能用位置
- 不能用关键字(keyword)
- 那和纯位置相对的
- 纯关键字(keyword only)
- 如何理解呢🤔
- 我们下次再说👋
- 本文来自 oeasy Python 系统教程。
- 想完整、扎实学 Python,
- 搜索 oeasy 即可。







