#1.长度判断与限制
# "raise" 是一个 Python 中用于抛出异常的关键字这允许程序员在发生错误或不符合预期条件的情况下,
# 提前终止程序的执行并给出相应的错误信息。
def ren(name: str, age: int):if len(name) > 3:raise ValueError("Name length should not exceed 20 characters")#"raise" 是一个 Python 中用于抛出异常的关键字print(name, age)
ren('给新事1',20)#2.长度判断与限制
text='zhang san is length should not exceed 20 characters'
#text='123'
limit=10
if len(text)>limit:text_1= text[:limit]text_2= text[:limit]+'...'print(text_1)print(text_2)
else:text=textprint(text)