“Jeśli typ to string Python” Kod odpowiedzi

Jeśli typ to string Python

isinstance(s, str)
Fair Fly

Python Sprawdź, czy zmienna to ciąg

# python 2
isinstance(s, basestring)

# python 3
isinstance(s, str)
Maks0bs

Sprawdź, czy ciąg to Python

# Method that checks if a string has python keywords, function calls or assignments
def pythonCheck(text):
    if re.search(r'^(for|while|if|def|try|except|else|elif|with|continue|break|#|from|import|return|pass|async|await|yield|raise|del|class|global|finally|assert)', text):
        return True

    # if it starts with a '(' then it's not python
    if re.search(r'^\(', text):
        return False

     # if it starts or ends with a '=' then it's not python
    if re.search(r'^=|=$', text):
        return False

    if re.search(r'\(|=', text):
        return True

    return False
Zé Pedro Mota

Odpowiedzi podobne do “Jeśli typ to string Python”

Pytania podobne do “Jeśli typ to string Python”

Więcej pokrewnych odpowiedzi na “Jeśli typ to string Python” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu