🔪 Delve into Python Strings: Super Bang Slicing! 🌟
Let's go to Basic Python on Strings! Today we're going to see the technique of cutting text, also called Slicing! It's very simple and useful.
Slicing uses the [start: end] sign to select the part of the String we want:
1.Basic Slicing: Print (b [2: 5])
• It will run from index 2 to before index 5 (index 5 will not be included!)
2.Slice From the Start: Print (b [: 5])
• If we leave the initial index, it starts to cut the first letter.
3.Slice To The End: Print (b [2:])
• If we leave the final index, it will cut from the given index to the last letter of the String.
4.Negative Indexing: Print (b [-5: -2])
• Use negative numbers to start counting from the end of the string! This example draws the character from the 5th position, from the end (-5) to the second position, from the end (-2).
Try to use this technique to handle text messages. It is a lot more convenient! Practice often and will be better by yourself. Fight! 💪💖
![ภาพแสดงการ Slicing แบบพื้นฐานใน Python โดยใช้ `print(b[2:5])` เพื่อตัดข้อความ "Hello, World!" ได้ผลลัพธ์เป็น "llo" ซึ่งเป็นการเลือกอักขระจากตำแหน่งที่ 2 ถึงก่อนตำแหน่งที่ 5.](https://p16-lemon8-sign-sg.tiktokcdn.com/tos-alisg-v-a3e477-sg/ooArDAbRYwAzsBBHPARlEILaAiP7u6iOiyBia~tplv-sdweummd6v-wap-logo-v1:QGRldl9zZWxmdGd0:1080:0.webp?lk3s=66c60501&source=wap_large_logo_image&x-expires=1778198400&x-signature=33CAarfU9mAMmdBMFNDPLMAs5B0%3D)
![ภาพแสดงการ Slicing จากจุดเริ่มต้นใน Python โดยใช้ `print(b[:5])` เพื่อตัดข้อความ "Hello, World!" ได้ผลลัพธ์เป็น "Hello" ซึ่งเป็นการเลือกอักขระตั้งแต่ตัวแรกถึงก่อนตำแหน่งที่ 5.](https://p16-lemon8-sign-sg.tiktokcdn.com/tos-alisg-v-a3e477-sg/oA6aQYHqARslAOAiiigPRIEYyD7BAwPBuBbbA~tplv-sdweummd6v-wap-logo-v1:QGRldl9zZWxmdGd0:1080:0.webp?lk3s=66c60501&source=wap_large_logo_image&x-expires=1778198400&x-signature=cww63IEX0Wz0H3symY9zeZ7mVHg%3D)
![ภาพแสดงการ Slicing ไปจนถึงจุดสิ้นสุดใน Python โดยใช้ `print(b[2:])` เพื่อตัดข้อความ "Hello, World!" ได้ผลลัพธ์เป็น "llo, World!" ซึ่งเป็นการเลือกอักขระตั้งแต่ตำแหน่งที่ 2 จนถึงตัวสุดท้าย.](https://p16-lemon8-sign-sg.tiktokcdn.com/tos-alisg-v-a3e477-sg/oMPOZEPz6yAAAkHBAYAI7iliDhRuwaBbcsRBi~tplv-sdweummd6v-wap-logo-v1:QGRldl9zZWxmdGd0:1080:0.webp?lk3s=66c60501&source=wap_large_logo_image&x-expires=1778198400&x-signature=B63pTA%2BKPJC0RK3jJnfM8F9GXdk%3D)
![ภาพแสดงการ Slicing โดยใช้ Negative Indexing ใน Python โดยใช้ `print(b[-5:-2])` เพื่อตัดข้อความ "Hello, World!" ได้ผลลัพธ์เป็น "orl" ซึ่งเป็นการเลือกอักขระจากท้ายสตริง.](https://p16-lemon8-sign-sg.tiktokcdn.com/tos-alisg-v-a3e477-sg/owbBAIYy6BBsHAilsAAhPEad7QRwAADiOuiRP~tplv-sdweummd6v-wap-logo-v1:QGRldl9zZWxmdGd0:1080:0.webp?lk3s=66c60501&source=wap_large_logo_image&x-expires=1778198400&x-signature=ojGXUSPIKJsOIh1xY%2FjGE5SQgzc%3D)






























































































