Tipe data string adalah salah satu tipe data penting dalam pemrograman Python. String sendiri adalah serangkaian karakter atau huruf yang diapit oleh tanda petik tunggal ('...') atau tanda petik ganda ("...").
Karakteristik dari tipe data string ini adalah sifatnya yang bersifat immutable atau tidak bisa diubah.
Dalam Python, terdapat berbagai operasi yang dapat dilakukan dengan tipe data string, seperti penggabungan string atau concatenation, pemotongan string atau slicing, dan pencarian substring atau substring search.
Berikut adalah beberapa operasi yang diperbolehkan pada tipe data string di Python:
1. Concatenation atau penggabungan string
Operasi ini dilakukan dengan menggunakan operator '+' atau dengan menggunakan method 'join()'.
Contoh penggunaannya adalah sebagai berikut:
2. Slicing atau pemotongan string
Operasi ini dilakukan dengan menggunakan operator '[]' dan dua angka yang menunjukkan indeks awal dan akhir pemotongan.
Contoh penggunaannya adalah sebagai berikut:
3. Substring search atau pencarian substring
Operasi ini dilakukan dengan menggunakan method 'find()' atau 'index()'. Kedua method ini akan mencari substring tertentu pada string dan mengembalikan indeks pertama kemunculan substring tersebut.
Perbedaannya, jika substring tidak ditemukan, method 'find()' akan mengembalikan nilai -1 sedangkan method 'index()' akan menimbulkan exception ValueError.
Contoh penggunaannya adalah sebagai berikut:
Dalam penggunaannya, tipe data string dapat digunakan dalam berbagai kasus seperti dalam penyimpanan data teks, pengolahan data teks, manipulasi dan pemrosesan teks pada program, dan banyak lagi.
Oleh karena itu, memahami karakteristik tipe data string dan operasi yang diperbolehkan dalam tipe data string di Python sangat penting bagi seorang programmer.
Artikel Lainnya Dengan Kategori Terkait :
1. Belajar Python #01 Mengenal PythonMen
2. Belajar Python #02 Instalasi dan Setup Python 3
3. Belajar Python #03 Membuat Kode Python pada Kode Editor
4. Belajar Python #04 Python Syntax - Print Function
5. Belajar Python #05 Python Syntax - Comment
6. Belajar Python #06 Error pada Python
7. Belajar Python #07 Klasifikasi Tipe Data
8. Belajar Python #08 Rangkuman struktur data
9. Belajar Python #09 Cara Membedakan dan Mengetahui Tipe Data
10. Belajar Python #10 Cara Mengubah Tipe Data
11. Belajar Python #11 Tipe Data String
12. Belajar Python #12 String Indexing
13. Belajar Python #13 Operator Basic
14. Belajar Python #14 Penggunaan Operator
15. Belajar Python #15 Prioritas Operator
16. Belajar Python #16 Built-in Function
17. Belajar Python #17 Tipe Data Built-in Function
18. Belajar Python #18 Variabel
19. Belajar Python #19 Deklarasi Variabel
20. Belajar Python #20 Variable Assignment
21. Belajar Python #21 Compound Assignment Operators
22. Belajar Python #22 Operator Aritmatika
23. Belajar Python #23 Variabel - Input Function
24. Belajar Python #24 Comparison Operators
25. Belajar Python #25 Comparison Operator Is & In
26. Belajar Python #26 Built-in Function
27. Belajar Python #27 Logical Operators
28. Belajar Python #28 Selection Structure Concept
29. Belajar Python #29 If Statement Syntax
30. Belajar Python #30 Indentation
31. Belajar Python #31 Pass keyword
32. Belajar Python #32 Elif Statement
33. Belajar Python #33 If-Else Statement
34. Belajar Python #34 Nested Conditional Statement
35. Belajar Python #35 Basic loop - loop
36. Belajar Python #36 Basic Loop - For Loop Syntax
37. Belajar Python #37 Sequence Object Iteration
38. Belajar Python #38 While vs For Loop
39. Belajar Python #39 While Loop Syntax
40. Belajar Python #40 Break vs Continue Keywords
41. Belajar Python #41 Nested Loop
42. Belajar Python #42 Mutable vs Immutable Data Types
43. Belajar Python #43 List - Declaration
44. Belajar Python #44 List - Indexing
45. Belajar Python #45 List - Addition and Deletion
46. Belajar Python #46 Basic Loop - For Loop Syntax
47. Belajar Python #47 List - Slicing
48. Belajar Python #48 List - In Operator
50. Belajar Python #50 Sequence Data Type
51. Belajar Python #51 Sequence Data Types - Iterator
52. Belajar Python #52 Sequence Data Types - Count Method
53. Belajar Python #53 Sequence Data Types - Linking
54. Belajar Python #54 Sequence Data Types - Operators
55. Belajar Python #55 Dictionary - Basics
56. Belajar Python #56 Dictionary - Key Value Pair
57. Belajar Python #57 Dictionary - Adding, Modifying, Delete Values
58. Belajar Python #58 Dictionary - Function and Operators
59. Belajar Python #59 JSON Datatypes - Basics
60. Belajar Python #60 JSON-Read and Exporting
61. Belajar Python #61 Creating 2D Lists
62. Belajar Python #62 Indexing 2D Lists
63. Belajar Python #63 2D Lists dengan Single For Loop
64. Belajar Python #64 2D Lists dengan Double For Loop
65. Belajar Python #65 Dictionary - Get Method
66. Belajar Python #66 Dictionary - Pop, PopItem, Clear Method
67. Belajar Python #67 Dictionary - Items, Keys, Values
68. Belajar Python #68 Dictionary - Update
69. Belajar Python #69 Dictionary - Update
70. Belajar Python #70 Dictionary - Assignment and Copying Method
71. Belajar Python #71 Dictionary - Default Dict
72. Belajar Python #72 Dictionary - Double Dictionary
73. Belajar Python #73 Dictionary - From Keys Method
74. Belajar Python #73 Dictionary - From Keys Method
75. Belajar Python #74 Set - Definiton
76. Belajar Python #75 Set - Check Value in Sets
77. Belajar Python #76 Set - Union and Intersections
78. Belajar Python #77 Set - Difference Of Set
79. Belajar Python #78 Set - Symmetric Difference
Mahardika Oktadiansyah - 17 April 2025
Belajar CSS Lanjutan #122 | Responsive Web Design - Images
Mahardika Oktadiansyah - 17 April 2025
Belajar CSS Lanjutan #121 | Responsive Web Design - Media Queries
Mahardika Oktadiansyah - 17 April 2025
Belajar CSS Lanjutan #120 | Responsive Web Design - Building a Grid View