Hướng dẫn python program to find uppercase letters - chương trình python để tìm chữ hoa

Đôi khi, trong khi làm việc với các chuỗi, chúng tôi lo ngại về độ nhạy của trường hợp của các chuỗi và có thể yêu cầu chỉ nhận được một trường hợp cụ thể của ký tự trong một chuỗi dài. Hãy để thảo luận về những cách nhất định trong đó chỉ có thể trích xuất các chữ cái chữ hoa từ một chuỗi.

Show

    Phương pháp số 1: Sử dụng danh sách hiểu + isupper () & nbsp; 

    Danh sách hiểu và chức năng isupper có thể được sử dụng để thực hiện nhiệm vụ cụ thể này. Độ hiểu hiểu danh sách chủ yếu được sử dụng để lặp lại trong danh sách và chức năng isupper kiểm tra các ký tự chữ hoa. & NBSP;

    Python3

    test_str = "

    GeeksForGeeKs & quot

    print

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    0

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    2
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    8

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9=
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    2
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4 test_str
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7

    print

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    0

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7

    Đầu ra: & nbsp;

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']

    Độ phức tạp về thời gian: O (n) O(n)

    Độ phức tạp không gian: O (n) O(n)

    Phương pháp số 2: Sử dụng Filter () + Lambda

    Chức năng lọc cùng với chức năng Lambda có thể được sử dụng để thực hiện nhiệm vụ cụ thể này. Hàm bộ lọc thực hiện lựa chọn cụ thể của các ký tự trường hợp và chức năng Lambda được sử dụng cho chuỗi truyền tải. & NBSP;

    Python3

    test_str = "

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    2
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4

    print

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    0

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    2
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    8

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9=
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    2
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4 test_str
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7

    print

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    0

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    4
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    3

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    1
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7

    Đầu ra: & nbsp;

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']

    Độ phức tạp về thời gian: O (n)O(n)

    Độ phức tạp không gian: O (n) O(n)

    Phương pháp số 2: Sử dụng Filter () + Lambda

    Python3

    Chức năng lọc cùng với chức năng Lambda có thể được sử dụng để thực hiện nhiệm vụ cụ thể này. Hàm bộ lọc thực hiện lựa chọn cụ thể của các ký tự trường hợp và chức năng Lambda được sử dụng cho chuỗi truyền tải. & NBSP;

    ________số 8

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9= test_str 4test_str 55556test_str 55555 test_str 9

    Phương pháp số 3: Không sử dụng các phương thức tích hợp

    test_str = "2

    printtest_str 55____75

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    8

    print4print5

    "9= GeeksForGeeKs & quot1

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9= GeeksForGeeKs & quot4

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']

    Độ phức tạp về thời gian: O (n) O(n)

    Độ phức tạp không gian: O (n) O(n)

    Phương pháp số 2: Sử dụng Filter () + Lambda Using ord() method.The ASCII value of the uppercase alphabet is from 65 to 90.

    Python3

    Chức năng lọc cùng với chức năng Lambda có thể được sử dụng để thực hiện nhiệm vụ cụ thể này. Hàm bộ lọc thực hiện lựa chọn cụ thể của các ký tự trường hợp và chức năng Lambda được sử dụng cho chuỗi truyền tải. & NBSP;

    ________số 8

    Phương pháp số 3: Không sử dụng các phương thức tích hợp

    test_str = "2

    printtest_str 55____75

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    8

    print4print5

    "9= GeeksForGeeKs & quot1

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9= GeeksForGeeKs & quot4

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']

    Độ phức tạp về thời gian: O (n)O(n)

    Độ phức tạp không gian: O (n)O(n)

    Phương pháp số 2: Sử dụng Filter () + Lambda

    Python3

    Chức năng lọc cùng với chức năng Lambda có thể được sử dụng để thực hiện nhiệm vụ cụ thể này. Hàm bộ lọc thực hiện lựa chọn cụ thể của các ký tự trường hợp và chức năng Lambda được sử dụng cho chuỗi truyền tải. & NBSP;

    ________số 8

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9= test_str 4test_str 55556test_str 55555 test_str 9

    test_str = "2

    printtest_str 55____75

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    6
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    7
    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    8

    "9= GeeksForGeeKs & quot1

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9= GeeksForGeeKs & quot4

    "9= GeeksForGeeKs & quot1

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']
    9= GeeksForGeeKs & quot4

    The original string is : GeeksForGeeKs
    The uppercase characters in string are : ['G', 'F', 'G', 'K']