How to check if the last letter in the string is a big letter python

Method 1

def method_1(s: str):
    r = re.search(r'.*[A-Z]$', s)
    if r:
        return True
    else:
        return False

Method 2

def method_2(s: str):
    return s[-1].isupper()

Method 3

def method_3(s: str):
    return 'A' <= s[-1] <= 'Z'

Execution testing

import re
import timeit


def method_1(s: str):
    r = re.search(r'.*[A-Z]$', s)
    if r:
        return True
    else:
        return False


def method_2(s: str):
    return s[-1].isupper()


def method_3(s: str):
    return 'A' <= s[-1] <= 'Z'


def main():

    time = timeit.repeat(lambda: method_1("fffG"))
    print("Method 1 time - ", time)
    time = timeit.repeat(lambda: method_2("gggG"))
    print("Method 2 time - ", time)
    time = timeit.repeat(lambda: method_3("gggG"))
    print("Method 3 time - ", time)


if __name__ == "__main__":
    main()

Output

Method 1 time -  [1.2294334, 1.3634751, 1.2222022, 1.2679466000000001, 1.1414464000000004]
Method 2 time -  [0.2178635, 0.2641372999999998, 0.24614259999999977, 0.2204689000000002, 0.21423919999999974]
Method 3 time -  [0.22135119999999997, 0.27477399999999985, 0.23235910000000004, 0.2425834999999985, 0.230558499999999]

You can see that method 2 (s[-1].isupper() ) is the fastest.