python3.5用了差不多一年了 和2.7有什么差别呢 就知道一个print,马丹的直接去官网看看去

1新语法

2新模块

def greeting(name: str) -> str:
    return 'Hello ' + name

- zipapp 打包python包为一个文件

ls myapp/

__main__.py 1.py 2.py

python -mzipapp myapp

python myapp.pyz 

python -mzipapp myapp -p "/usr/bin/env python"

./myapp.pyz

3新内建特征

#!/usr/bin/env python
"""
python async
"""
---
#python3.4的异步io
import threading
import asyncio

@asyncio.coroutine
def hello():
    print('Hello world1! (%s)' % threading.currentThread())
    yield from asyncio.sleep(1)
    print('Hello again1! (%s)' % threading.currentThread())

loop = asyncio.get_event_loop()
tasks = [hello(), hello()]
#print(hello,hello(),hello._is_coroutine)
#<function hello at 0x7fcc1d82c8c8> <generator object hello at 0x7fcc1ab63eb8> True
#hello 已经是generator 协程函数了
loop.run_until_complete(asyncio.wait(tasks))


#python3.5 使用async和await是针对coroutine的新语法
#把@asyncio.coroutine替换为async;
#把yield from替换为await。


async def hello2():
    print('Hello world2! (%s)' % threading.currentThread())
    r= await hello()
    print('Hello again2! (%s)' % threading.currentThread())

loop.run_until_complete(asyncio.wait([hello2(),hello2()]))
loop.close()

结果:

Hello world1! (<_MainThread(MainThread, started 140260639328000)>)
Hello world1! (<_MainThread(MainThread, started 140260639328000)>)
#sleep 1
Hello again1! (<_MainThread(MainThread, started 140260639328000)>)
Hello again1! (<_MainThread(MainThread, started 140260639328000)>)
Hello world2! (<_MainThread(MainThread, started 140260639328000)>)
Hello world1! (<_MainThread(MainThread, started 140260639328000)>)
Hello world2! (<_MainThread(MainThread, started 140260639328000)>)
Hello world1! (<_MainThread(MainThread, started 140260639328000)>)
#sleep 1
Hello again1! (<_MainThread(MainThread, started 140260639328000)>)
Hello again2! (<_MainThread(MainThread, started 140260639328000)>)
Hello again1! (<_MainThread(MainThread, started 140260639328000)>)
Hello again2! (<_MainThread(MainThread, started 140260639328000)>)

学习资料