比如 print 成为了函数;还有编码的问题,Python3 中不再有 Unicode 对象,默认 str 就是 Unicode;除法也有所变化,比如 Python3 除法返回的是浮点数。 Python2 里面是没有类型申明的,Python3 中我们可以添加一个类型注解(type hint),帮助IDE实现类型提示以及类型检查(mypy)。Python3 中优化的 super() 方便直接调用...
除法变化,Python3除号(/)返回浮点数,Python2向下取整,Python3向下取整为(//) 类型注解(type hint)。帮助IDE实现类型检查; 主要是提示作用,检查可以用mypy包 优化的super()函数方便直接调用父类函数; 高级解包操作:a,b,*rest=range(10) 限定关键字参数(Keyword only arguments),防止把数据搞混 Chained exceptions。
asyncio内置库,async/await原生协程支持异步编程; 新的内置库enum(枚举),mock(单测),asyncio(异步),ipaddress(处理ip地址),concurent.futures等 Python/2/3兼容工具: six模块;2to3等工具转换代码;__future__ 9. Python函数常考题: Python如何传递参数: 传递值还是引用?都不是,唯一支持的参数传递是共享传参; ...
asyncio内置库,async/await原生协程支持异步编程; 新的内置库enum(枚举),mock(单测),asyncio(异步),ipaddress(处理ip地址),concurent.futures等 Python/2/3兼容工具: six模块;2to3等工具转换代码;__future__ 9. Python函数常考题: Python如何传递参数: 传递值还是引用?都不是,唯一支持的参数传递是共享传参; ...
一、Type hint 首要的是尽可能使用类型提示,特别是在函数签名和类属性中。当我读到一个像这样的函数签名时: def find_item(records, check): 1. 我不知道签名本身发生了什么。是records列表、字典还是数据库连接?是check布尔值还是函数?这个函数返回什么?如果失败会发生什么,它会引发异常还是返回None?为了找到这些...
Python2/3差异 Python3改进 print 成为函数 编码问题。Python3 不再有Unicode对象, 默认 str 就是unicode 除法变化。Python3除号返回浮点数 类型注解(type hint) 帮助IDE实现类型检查 # 只能做类型提示,不能进行检查, def hello(name:str) -> str:
最常见的基本类型就是布尔类型了,其值就是 true 或者 false,类型声明用 boolean 就好了,在 TypeScript 中,声明一个 boolean 类型的变量写法如下: 这里注意到,声明类型可以在变量名的后面加上一个冒号,然后跟一个类型声明,和 Python 的 Type Hint 非常像。然后我们用 console 的 log 方法输出了这个变量,并用 ...
parameter, variable, property, enumMember function, member module intrinsic magicFunction (dunder methods) selfParameter, clsParameter 修饰符 declaration readonly, static, abstract async typeHint, typeHintComment decorator builtin 范围检查器工具使您可以探索源文件中存在哪些语义标记以及它们匹配的主题规则。
class Field:def __init__(self, name: str, constructor: Callable) -> None:if not callable(constructor) or constructor is type(None):raise TypeError(f'{name!r} type hint must be callable')self.name = nameself.storage_name = '_' + name # ①self.constructor = constructordef __get__(...
类型注解(type hint)。帮助IDE实现类型检查 def hello(name: str) -> str: return 'hello' + name 优化的super()方便直接调用父类函数 class Base(object): def hello(self): print('say hello') class C(Base): def hello(self): # py2 return super(C, self).hello() class C2(Base): def...