In [28]: %%cython
...: from cpython.set cimport PySet_Pop
...: a={1,2,3,4,5}
...: print(PySet_Pop(a))
...: print(a)
...:
1
{2, 3, 4, 5}
In [29]: %%cython
...: from numpy.math cimport PI
...: print(PI)
...:
3.141592653589793
In [30]: %%cython
...: from numpy.math cimport E
...: print(E)
...:
2.718281828459045
In [32]: %%cython
...: from libc.math cimport sin
...: cdef int a=30...: print(sin(a/180))
...:
0.16589613269341502
In [33]: %%cython
...: cdef extern from "math.h":
...: double sin(double x)
...: print(sin(30/180))
...:
0.16589613269341502
# 动态链接from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
ext_modules=[
Extension("demo",
sources=["demo.pyx"],
libraries=["m"] # Unix-like specific
)
]
setup(
name = "Demos",
ext_modules = cythonize(ext_modules)
)
In [42]: %%cython
...: from libc.string cimport strstr
...: cdef char* data = "hfvcakdfagbcffvschvxcdfgccbcfhvgcsnfxjh"...: pos = strstr(needle='akd', haystack=data)
...: print (pos)
...:
b'akdfagbcffvschvxcdfgccbcfhvgcsnfxjh'
In [3]: %%cython
...: cdef extern from "string.h":
...: char* strstr(const char *haystack, const char *needle)
...: cdef char* data = "hfvcakdfagbcffvschvxcdfgccbcfhvgcsnfxjh"...:
...: pos = strstr(needle='akd', haystack=data)
...: print(pos)
...:
...:
b'akdfagbcffvschvxcdfgccbcfhvgcsnfxjh'