Hướng dẫn split each character in a string python - tách từng ký tự trong chuỗi python

Đưa ra một chuỗi, hãy viết một chương trình Python để chia các ký tự của chuỗi đã cho thành một danh sách bằng Python.

Examples:    

Input : geeks
Output : ['g', 'e', 'e', 'k', 's']

Input : Word
Output : ['W', 'o', 'r', 'd']

Phương pháp 1: Chia một chuỗi thành danh sách Python bằng phương thức unpack (*)

Hành động giải nén liên quan đến việc loại bỏ mọi thứ, cụ thể là các vòng lặp như từ điển, danh sách và bộ dữ liệu.

Python3

['g', 'e', 'e', 'k', 's']
2
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
4

['g', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
6
['g', 'e', 'e', 'k', 's']
7
['g', 'e', 'e', 'k', 's']
8

Output:  

['g', 'e', 'e', 'k', 's']

Phương pháp 2: Chia một chuỗi thành danh sách Python bằng cách sử dụng vòng lặp

Ở đây, chúng tôi đang chia các chữ cái bằng cách sử dụng bản địa bằng cách sử dụng vòng lặp và sau đó chúng tôi đang nối nó vào một danh sách mới.

Python3

['g', 'e', 'e', 'k', 's']
2
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
1

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
2
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
4

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
6
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
7
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
8

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
9
['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
0

['g', 'e', 'e', 'k', 's']
5
['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
2

Output:

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']

Phương pháp 3: Chia một chuỗi thành danh sách python bằng cách sử dụng danh sách hiểu

Cách tiếp cận này sử dụng danh sách hiểu để chuyển đổi từng ký tự thành một danh sách. Sử dụng cú pháp sau, bạn có thể chia các ký tự của chuỗi thành danh sách.

Python3

['g', 'e', 'e', 'k', 's']
2
['g', 'e', 'e', 'k', 's']
3
['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
5

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
6
['g', 'e', 'e', 'k', 's']
3
['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
8
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
0
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
7
['g', 'e', 'e', 'k', 's']
2

['g', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
4

Output:  

['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']

Phương pháp 4: Chia một chuỗi thành danh sách Python bằng Danh sách () & NBSP; Typecasting

Python cung cấp đánh máy trực tiếp các chuỗi vào danh sách bằng danh sách Python ().

Python3

['g', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
6

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
9
['g', 'e', 'e', 'k', 's']
8
['g', 'e', 'e', 'k', 's']
9
['G', 'e', 'e', 'k', 's', '@', 'f', 'o', 'r']
0

['G', 'e', 'e', 'k', 's', '@', 'f', 'o', 'r']
1
['g', 'e', 'e', 'k', 's']
3
['G', 'e', 'e', 'k', 's', '@', 'f', 'o', 'r']
3

['g', 'e', 'e', 'k', 's']
5
['G', 'e', 'e', 'k', 's', '@', 'f', 'o', 'r']
5

Output:  

['g', 'e', 'e', 'k', 's']

Phương pháp 5: Chia một chuỗi thành danh sách Python bằng cách sử dụng Extend ()

Mở rộng lặp lại qua đầu vào của nó, mở rộng danh sách và thêm từng thành viên.

Python3

['g', 'e', 'e', 'k', 's']
2
['g', 'e', 'e', 'k', 's']
3
['G', 'e', 'e', 'k', 's', '@', 'f', 'o', 'r']
8

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
2
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
4

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2

['g', 'e', 'e', 'k', 's']
5
['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
2

Output:  

['G', 'e', 'e', 'k', 's', '@', 'f', 'o', 'r']

Phương thức số 4: Sử dụng phương thức Jop () + split ()

Chúng ta có thể sử dụng phương thức đề cập ở trên để phân chia chuỗi trong danh sách ký tự. Tham gia được sử dụng để thêm khoảng cách giữa ký tự của chuỗi và chia được sử dụng để phân chia ký tự giữa không gian trong chuỗi. & NBSP;

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

Python3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
0
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
40

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
4
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
43
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
45

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5

Đầu ra

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']

Phương thức số 5: Sử dụng phương thức re.findall (): Chúng ta có thể sử dụng phương thức đề cập ở trên để tìm tất cả ký tự trong chuỗi và tạo thành một danh sách các ký tự. 

Python

Python3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
0
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
40

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5

Đầu ra

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']

Phương thức số 5: Sử dụng phương thức re.findall (): Chúng ta có thể sử dụng phương thức đề cập ở trên để tìm tất cả ký tự trong chuỗi và tạo thành một danh sách các ký tự.

Python

Python3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
0
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
4
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
['g', 'e', 'e', 'k', 's']
18
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
['g', 'e', 'e', 'k', 's']
20
['g', 'e', 'e', 'k', 's']
21

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5

Đầu ra

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']

Phương thức số 4: Sử dụng phương thức Jop () + split ()

Chúng ta có thể sử dụng phương thức đề cập ở trên để phân chia chuỗi trong danh sách ký tự. Tham gia được sử dụng để thêm khoảng cách giữa ký tự của chuỗi và chia được sử dụng để phân chia ký tự giữa không gian trong chuỗi. & NBSP;

Python3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
0
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
40

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
4
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
43
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
45

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5

Đầu ra

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']

Phương thức số 4: Sử dụng phương thức Jop () + split () Using re.findall() method: We can use above mention method to find all character in the string and form a list of characters.

Chúng ta có thể sử dụng phương thức đề cập ở trên để phân chia chuỗi trong danh sách ký tự. Tham gia được sử dụng để thêm khoảng cách giữa ký tự của chuỗi và chia được sử dụng để phân chia ký tự giữa không gian trong chuỗi. & NBSP;

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
7

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
0
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
40

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5

Đầu ra

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']

Phương thức số 4: Sử dụng phương thức Jop () + split ()

Python3

Chúng ta có thể sử dụng phương thức đề cập ở trên để phân chia chuỗi trong danh sách ký tự. Tham gia được sử dụng để thêm khoảng cách giữa ký tự của chuỗi và chia được sử dụng để phân chia ký tự giữa không gian trong chuỗi. & NBSP;

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
0
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
3

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
40

The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
4
['g', 'e', 'e', 'k', 's']
3
['g', 'e', 'e', 'k', 's']
43
['g', 'e', 'e', 'k', 's']
39
['g', 'e', 'e', 'k', 's']
45

['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']
9
['g', 'e', 'e', 'k', 's']
91

['g', 'e', 'e', 'k', 's']
5
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
9
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
1
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
2
The original string is : GeeksforGeeks
The resultant list of characters : ['G', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'G', 'e', 'e', 'k', 's']
5

Đầu ra

['g', 'e', 'e', 'k', 's']
1