# How to use 'python square root' in Python

Every line of 'python square root' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure. ## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``632def square_root(self):633    """634    Return square root, which is a complex number.635636    EXAMPLES:637        sage: i = ComplexField(100).0638        sage: (-i).sqrt()639        0.70710678118654752440084436210459 - 0.70710678118654752440084436210459*I640    """641    return self.sqrt()``
``66def square_root_mod_p(a, p):67    """68    Iterator yielding values v s.t. v * v % p == a69    There will be 0 or 2 answers.70    """71    # see http://course1.winona.edu/eerrthum/13Spring/SquareRoots.pdf72    a %= p73    if p == 2:74        yield a & 175        return76    if p == 4:77        a &= 378        if a == 0:79            yield 080        if a == 1:81            yield 182            yield 383        return84    if p & 3 == 3:85        s1 = pow(a, (p + 1) >> 2, p)86        if s1 * s1 % p == a:87            yield s188            yield p - s189        return90    if p & 7 == 5:91        k = (p - 5) >> 392        v1 = pow(a, (p-1) >> 2, p)93        v2 = pow(a, k+1, p)94        if v1 == 1:95            yield v296            yield p - v297        elif v1 == p-1:98            r = (v2 * pow(2, 2*k+1, p)) % p99            yield r100            yield p - r101        return102    else:103        raise ValueError("not implemented for prime %d" % p)``