Hướng dẫn how do i check if a string subsets in python? - làm cách nào để kiểm tra xem một tập hợp con chuỗi trong python?

Cải thiện bài viết

Show

Lưu bài viết

Đôi khi, trong khi làm việc với các chuỗi, chúng ta có thể có một vấn đề trong đó chúng ta cần kiểm tra xem một chuỗi là một phần sau của một chuỗi khác. Điều này có thể có ứng dụng có thể trong nhiều lĩnh vực bao gồm khoa học dữ liệu và lập trình hàng ngày. Hãy thảo luận về những cách nhất định trong đó nhiệm vụ này có thể được thực hiện. & NBSP;

Phương pháp số 1: Sử dụng tất cả () Đây là một trong những điều mà chúng ta có thể giải quyết vấn đề này. Trong đó, chúng tôi sử dụng tất cả () để kiểm tra xem tất cả các ký tự của một chuỗi có mặt trong một chuỗi khác. & NBSP; This is one of the by which we can solve this problem. In this, we employ all() to check if all the characters of one string are present in another. 

Python3

test_str1 = "geeksforgeeks"

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
0=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
2

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
5
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
6
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
8=
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
0
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
1
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
2

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Yes! it is present in the string
0
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
6
Yes! it is present in the string
2
Yes! it is present in the string
3

Đầu ra: & nbsp;

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True

& nbsp; Phương pháp số 2: Sử dụng assubset () sử dụng hàm sẵn là một trong những cách mà nhiệm vụ này có thể được thực hiện. Trong đó, chúng tôi chỉ sử dụng chức năng và nó trả về kết quả sau khi xử lý nội bộ. & NBSP;Method #2 : Using issubset() Using an inbuilt function is one of the ways in which this task can be performed. In this, we just employ the function and it returns the result after internal processing. 

Python3

test_str1 = "geeksforgeeks"

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
0=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
2

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
5
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
6
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
8=
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
0
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
1
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
2

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Yes! it is present in the string
0
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
6
Yes! it is present in the string
2
Yes! it is present in the string
3

Đầu ra: & nbsp;

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True

& nbsp; Phương pháp số 2: Sử dụng assubset () sử dụng hàm sẵn là một trong những cách mà nhiệm vụ này có thể được thực hiện. Trong đó, chúng tôi chỉ sử dụng chức năng và nó trả về kết quả sau khi xử lý nội bộ. & NBSP;

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
8=
16
7
16
8
O(n)

Độ phức tạp về thời gian và không gian cho tất cả các phương pháp là như nhau:O(n)


The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
31"geeksforgeeks"0
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
49
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
2

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes

Phương pháp: Sử dụng chức năng Lambda

Cácin” operator which is used as a comparison operator. Here we will cover different approaches like:

  • The original string is : geeksforgeeks
    Does string contains all the characters of other list? : True
    3
    Example 1: Input : Substring = "geeks" 
               String="geeks for geeks"
    Output : yes
    Example 2: Input : Substring = "geek"
               String="geeks for geeks"
    Output : yes
    31"geeksforgeeks"0
    Yes! Geeks-13 is containing.
    Yes! Geeks-78 is containing.
    8
    Example 1: Input : Substring = "geeks" 
               String="geeks for geeks"
    Output : yes
    Example 2: Input : Substring = "geek"
               String="geeks for geeks"
    Output : yes
    60
    NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
    7 "geeksforgeeks"7__
  • Phương pháp: Sử dụng chức năng Countof & nbsp;
  • The original string is : geeksforgeeks
    Does string contains all the characters of other list? : True
    94
    Example 1: Input : Substring = "geeks" 
               String="geeks for geeks"
    Output : yes
    Example 2: Input : Substring = "geek"
               String="geeks for geeks"
    Output : yes
    65
  • Example 1: Input : Substring = "geeks" 
               String="geeks for geeks"
    Output : yes
    Example 2: Input : Substring = "geek"
               String="geeks for geeks"
    Output : yes
    27=test_str1 9
  • The original string is : geeksforgeeks
    Does string contains all the characters of other list? : True
    3
    Example 1: Input : Substring = "geeks" 
               String="geeks for geeks"
    Output : yes
    Example 2: Input : Substring = "geek"
               String="geeks for geeks"
    Output : yes
    31"geeksforgeeks"0
    Yes! Geeks-13 is containing.
    Yes! Geeks-78 is containing.
    8
    Example 1: Input : Substring = "geeks" 
               String="geeks for geeks"
    Output : yes
    Example 2: Input : Substring = "geek"
               String="geeks for geeks"
    Output : yes
    76
    The original string is : geeksforgeeks
    Does string contains all the characters of other list? : True
    34
    NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
    7 "geeksforgeeks"7__
  • Trong bài viết này, chúng tôi sẽ đề cập đến cách kiểm tra xem chuỗi Python có chứa một chuỗi khác hoặc một chuỗi con trong Python không. Cho hai chuỗi, hãy kiểm tra xem một chuỗi con có có trong chuỗi đã cho hay không. & NBSP;
  • Python có một chuỗi chứa phương thức chuỗi con không

Có, kiểm tra một chuỗi con là một trong những nhiệm vụ được sử dụng nhiều nhất trong Python. Python sử dụng nhiều phương thức để kiểm tra một chuỗi có chứa chuỗi con như, find (), index (), Count (), v.v. . Ở đây chúng tôi sẽ bao gồm các cách tiếp cận khác nhau như:

Python3

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
5=
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
99= test_str1 9

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
5
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
7
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
8

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4test_str1 2
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

Đầu ra

Yes! it is present in the string

Phương pháp 7: Kiểm tra chuỗi con & nbsp; sử dụng biểu thức thông thường & nbsp;

Regex có thể được sử dụng để kiểm tra xem một chuỗi có chứa mẫu tìm kiếm được chỉ định không. Python có một gói tích hợp có tên Re, có thể được sử dụng để làm việc với các biểu thức thông thường. & NBSP;

Python3

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
94
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
95

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
5=
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
99= test_str1 9

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
03

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4"geeksforgeeks"0
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
7
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
8

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4"geeksforgeeks"7
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 2The original string is : geeksforgeeks Does string contains all the characters of other list? : True3The original string is : geeksforgeeks Does string contains all the characters of other list? : True4Example 1: Input : Substring = "geeks" String="geeks for geeks" Output : yes Example 2: Input : Substring = "geek" String="geeks for geeks" Output : yes07 Example 1: Input : Substring = "geeks" String="geeks for geeks" Output : yes Example 2: Input : Substring = "geek" String="geeks for geeks" Output : yes08Example 1: Input : Substring = "geeks" String="geeks for geeks" Output : yes Example 2: Input : Substring = "geek" String="geeks for geeks" Output : yes09The original string is : geeksforgeeks Does string contains all the characters of other list? : True4

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
18
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
08
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4

Python3

"geeksforgeeks"9

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
00

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
03==
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
06
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
07
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
08

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
12
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
7
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
8

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
20
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

test_str1 4= test_str1 6

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
25=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
27

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
28

Phương pháp 4: Kiểm tra Subring & NBSP; sử dụng phương thức đếm () Phương thức

Bạn cũng có thể đếm số lần xuất hiện của một chuỗi con cụ thể trong một chuỗi, sau đó bạn có thể sử dụng phương thức Python Count (). Nếu không tìm thấy chất nền thì không có, thì có, sẽ không in nếu không sẽ không được in.

Python3

"geeksforgeeks"9

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
30

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
33
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
34
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
08

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
20
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
7
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
8

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
12
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
49=
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
52= test_str1 9

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
55

Phương pháp 5: Kiểm tra chuỗi con bằng phương thức Index ()

Phương thức .index () Trả về chỉ số bắt đầu của chuỗi con được truyền dưới dạng tham số. Ở đây, Sub Substring có mặt tại INDEX 16..index() method returns the starting index of the substring passed as a parameter. Here “substring” is present at index 16.

Python3

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
56=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
58

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
59=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
34

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
62=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
64

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
66
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
67
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
68

Output:

16

Phương pháp 6: Kiểm tra chuỗi con & nbsp; sử dụng lớp __contains __, & nbsp; lớp ma thuật.

Chuỗi Python __Contains __ (). Phương thức này được sử dụng để kiểm tra xem chuỗi có mặt trong chuỗi khác hay không. & NBSP;

Python3

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
69=
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
71
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
72
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
73
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
74
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
73
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
76__

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
4
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
81
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
83

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
86
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
87
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
08

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
91
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
92
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
6

Đầu ra

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.

Phương pháp 7: Kiểm tra chuỗi con & nbsp; sử dụng biểu thức thông thường & nbsp;

Regex có thể được sử dụng để kiểm tra xem một chuỗi có chứa mẫu tìm kiếm được chỉ định không. Python có một gói tích hợp có tên Re, có thể được sử dụng để làm việc với các biểu thức thông thường. & NBSP;re, which can be used to work with Regular Expressions. 

Python3

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
94
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
95

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
5=
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
99= test_str1 9

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
03

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
07
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
08
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
12

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
7
NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
8

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
18
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
08
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
09
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
12

Đầu ra

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 

Phương pháp 7: Kiểm tra chuỗi con & nbsp; sử dụng biểu thức thông thường & nbsp;

Python3

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
24=test_str1 6

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
27=test_str1 9

Regex có thể được sử dụng để kiểm tra xem một chuỗi có chứa mẫu tìm kiếm được chỉ định không. Python có một gói tích hợp có tên Re, có thể được sử dụng để làm việc với các biểu thức thông thường. & NBSP;

The original string is : geeksforgeeks Does string contains all the characters of other list? : True94 The original string is : geeksforgeeks Does string contains all the characters of other list? : True95

Python3

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
24=test_str1 6

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
27=test_str1 9

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
5=
Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
7

The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
99= test_str1 9

Yes! Geeks-13 is containing.
Yes! Geeks-78 is containing.
8
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
03
Using countof function 

Python3

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
07
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
08
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4

Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
24=test_str1 6

NO,string 'geeks' is not present in string 'A geek in need is a geek indeed' 
2
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
3
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
18
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
08
Example 1: Input : Substring = "geeks" 
           String="geeks for geeks"
Output : yes
Example 2: Input : Substring = "geek"
           String="geeks for geeks"
Output : yes
09
The original string is : geeksforgeeks
Does string contains all the characters of other list? : True
4

Phương pháp: Sử dụng danh sách hiểu & nbsp;