Automatically translated.View original post

🔪 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! 💪💖

# python # data # ai # programmer # learnonlemon8

2025/11/10 Edited to

... Read moreในภาษา Python เราจะใช้ชนิดข้อมูล str หรือ string เพื่อจัดการกับข้อความต่างๆ ซึ่ง str คือข้อมูลที่อยู่ในรูปของตัวอักษร เช่น ชื่อ, ประโยค หรือตัวเลขที่เก็บไว้ในรูปแบบข้อความ การเข้าใจและใช้งาน str อย่างถูกต้องจะช่วยให้คุณสามารถจัดการข้อความได้อย่างมีประสิทธิภาพมากขึ้น ตัวอย่างเช่น การใช้ slicing ที่ถือเป็นเครื่องมือสำคัญในการเลือกส่วนของข้อความที่ต้องการ ไม่ว่าจะเป็นการดึงคำบางคำ หรือทำการแก้ไขข้อความให้เหมาะสม นอกจากนี้ การใช้ดัชนีติดลบ (Negative Indexing) ยังช่วยให้เราสามารถเข้าถึงตำแหน่งตัวอักษรจากท้ายข้อความได้ ทำให้โค้ดดูเรียบง่ายขึ้นและใช้งานสะดวกมากยิ่งขึ้น จากภาพตัวอย่าง OCR ที่แสดงรายละเอียดการใช้ slicing ใน Python กับข้อความ "Hello, World!" ก็ยืนยันว่าเทคนิคนี้เป็นวิธีที่ยอดเยี่ยมและควรฝึกฝนสำหรับทุกคนที่เริ่มต้นเรียนรู้การเขียนโปรแกรมด้วย Python ลองนำเทคนิคการใช้ str และ slicing ไปใช้ในโปรเจกต์จริงดูนะคะ จะช่วยเพิ่มประสิทธิภาพและความคล่องตัวในการเขียนโค้ดได้ดีมากขึ้นทีเดียวค่ะ สู้ๆ! 💪

Related posts

My Programming Interest Just Skyrocketed! 🚀
I just discovered something that has made my interest in programming explode to 1000000000000000%! 🤯 🎮 Learning Programming is Like a Game Adventure! From Python, Java, JavaScript, to HTML, there are all kinds of programming languages available, along with systematic topic courses. The learning p
Valder

Valder

2164 likes

Shadow Work Journaling Prompts ✍🏻
Shadow work involves delving into the unconscious aspects of oneself, known as the "shadow," which encompasses hidden emotions, desires, fears, and traits often deemed unacceptable or repressed. It's a psychological process aimed at acknowledging, understanding, and integrating these da
mindofieva

mindofieva

493 likes

8 Free Online Certifications to Boost Your Resume
Hi, lemons! In today's competitive job market, having the right certifications can make a significant difference in showcasing your skills and expertise. Online certifications are not only convenient but also cost-effective. Here are six free online certifications that can give your resume a va
Lifestyle Babe

Lifestyle Babe

1212 likes

Books that left my jaw on the floor
Fair warning, friends: these books are NOT for the faint of heart. They're raw, intense, and full of messy emotions. They delve into darkness, pain, and the messy realities of life. But they also offer glimpses of hope, resilience, and the incredible strength of the human spirit. I've fe
Meredith Jao

Meredith Jao

9784 likes

Sweet Potato Ooey Gooey Butter Cake
If you love a rich, melt-in-your-mouth dessert… this one right here is dangerous 😮‍🔥 I took the classic Paula Deen ooey gooey butter cake and added my own twist; a layer of sweet potato filling baked right under that creamy, buttery cream cheese topping. Baby… it did NOT disappoint. That sweet p
Roe

Roe

1317 likes

👀🪴The Science ofWhy Plants BoostYour Mood🪴👀
🪴Incorporating more plant life into your home and routine can dramatically enhance your quality of life. 🪴From improving air quality to boosting your mood, the numerous benefits of plants are backed by science and are accessible to anyone willing to engage with nature. 🪴So, gather your pots, soil
Nature Elegance

Nature Elegance

38 likes

An overhead shot of feet in fuzzy slippers on a dark rug, with an iPad displaying '1, 2, 3' and a stylus. Pink text overlay reads '3 pass study method,' introducing a study technique.
A hand holds an iPad showing '1 recognize material,' '2 broader understanding,' and '3 tough concepts' on a grid background, detailing the steps of the '3 pass study method.'
A screenshot of an Instagram post by 'medical.morgan' explaining the '3 pass' study method, emphasizing the importance of the third pass for deep understanding and making connections.
How to become an academic weapon in 3 steps 🩷
Hey fellow students of Lemon8! I wanted to share a great new study technique I learned, called the three pass method. I’ve used this as a great way to work through long amounts of content, and organize my thoughts when learning new things. The first pass is simply for recognition, get yo
bea_studies_PA

bea_studies_PA

59 likes

ADHD: what you need to know!!
I, personally, am going through this phase right now to where I feel like every one I care about is turning away from me. That is why I decided to share this content for anyone that might be feeling the same… <3 ADHD’ers, UNITE! #rsdadhd #rsd
*ೃ༄Lera Batt *ೃ༄

*ೃ༄Lera Batt *ೃ༄

336 likes

1 Strategy To Resolve Relationship Conflict
Navigating conflicts in your relationship can be challenging, but with the right approach, you can turn disagreements into opportunities for growth. Here’s a personal strategy to help you and your partner resolve issues more effectively: S.I.T. D.O.W.N. Together • S: Set the Scene – Cr
Shawn McBride Speaks

Shawn McBride Speaks

236 likes

A flat lay of various Korean skincare products, including cleansers, toners, and serums, arranged on a pink fabric background. The image is adorned with decorative stars and bows, highlighting a collection of new beauty items.
A close-up of four Korean skincare products, including a cleansing oil, a cleansing foam, a soothing toner, and a cream in a tube, displayed on a wooden surface. The items are neatly arranged, showcasing a selection of beauty essentials.
Three beauty products are displayed on a desk, featuring a dropper bottle of serum, a lip balm stick, and a tube of cream. The items are positioned in front of a blurred background, highlighting a selection of personal care products.
YesStyle Korean Skincare Haul
I’ve heard endless good things about Korean skincare products, so I decided it was finally time to delve into something new. I’ll update with results! Products and prices are listed in the pictures. I ordered everything off of YesStyle, as I heard that was the best place to buy from. Although, it d
Kayley🌸

Kayley🌸

331 likes

A collage featuring Elicia Goguen, a laptop, self-care items, and a checklist for a 30-day glow-up challenge covering sleep, movement, nourishment, self-development, and self-care. The image introduces how to start and maintain a glow-up journey with habit trackers and templates.
Text outlining the first three takeaways for a 30-day glow-up challenge: starting the challenge for personal growth, prioritizing sleep for energy, and incorporating movement for physical well-being.
Text outlining takeaways 4, 5, and 6 for a glow-up challenge: focusing on nourishment over strict diets, committing one hour daily to self-development, and utilizing habit stacking for efficient self-development.
30-day glow up challenge and tips!
Great advice from Elicia on emarking on a 30-day glow up challenge to kickstart personal growth! 1) Starting a 30-day glow up challenge is crucial for personal growth. - Challenges like these can help individuals break out of slumps and establish consistent routines. - Setting specific goals
Elevate Mind

Elevate Mind

8 likes

A college campus scene with students walking, overlaid with text 'Freshmen Brainrot to Ivy League vibes' and decorative elements like pink lips and butterflies, promoting a transformation from brainrot to sophisticated vibes.
A phone screen showcasing study apps like Obsidian and Taskheat, and promoting BeFreed as a smart reading app that condenses 10K+ non-fiction books into 10-min skims, 20-min podcasts, or 30-min deep dives.
A phone screen displaying the BeFreed app, allowing users to turn books into personalized podcasts by selecting up to three books like 'Atomic Habits' and choosing podcast styles such as dialogue, female, or male voices.
Freshmen ✨Brainrot✨ to IVY LEAGUE vibes 🌸🤌💋🤧🌷📸
Yes, they’re free-ish and yes, they’ll make you feel smart 😏 📑📚 These apps helped me📚📑 1. Obsidian 🚂 – For serious note-takers who love linking ideas together like a mind map. 2. Taskheat 🔗– Turns your messy to-do list into a visual flowchart. 3. Bearable 🐾– Track mood, energy, habits, and s
ang3lie

ang3lie

2 likes

october tbr 🍂🪦🤎👻
do we think i can make it through all of these this month?😅 #booktok #bookstagram #readersoflemon8 #october #tbr
✰ ꜱᴋʏᴇ ☾

✰ ꜱᴋʏᴇ ☾

32 likes

Unseen Perks of Being a Transfer Student
🌆 1. Discover Your Ideal College Experience Your time at community college isn't just a stepping stone; it's a period of self-discovery. Do you see yourself thriving in a bustling city environment, or do you prefer the charm of a college town? Maybe it’s the allure of sunny weather or the
Lizz

Lizz

120 likes

Vintage Barbie: Iconic Looks & Grandma's Adorable Dresses We delve into the world of Vintage Barbie, exploring iconic styles. Inspired by a vision of a sage green room, blonde ponytail, and yellow outfit. We reminisce about adorable mod dresses crafted by our grandmother for our mother. #
Tigerriomusic

Tigerriomusic

0 likes

Hidden Signs of ADHD: Insights for Women
Hello honey ❤️ Living with ADHD is like navigating through a maze of surprises, and sometimes, the symptoms manifest in unexpected ways, especially for women. Let’s delve into some lesser-known ADHD symptoms that you might not expect but are more common than you think. Here’s the lowdown: 📌
Alena Artemenko

Alena Artemenko

107 likes

An assortment of colorful fruits like papaya, dragon fruit, pineapple, and oranges, with an overlay stating "3 fruit peels with high nutritional value that you've been throwing away," introducing the topic of beneficial fruit peels.
A graphic detailing the high nutritional value of dragon fruit peel, including its polyphenol and anthocyanin content, and suggesting consumption methods like blending, cold dishes, or making jellies/gummies.
A graphic highlighting the nutritional benefits of watermelon rinds, specifically its high vitamin C and amino acid content, and offering preparation ideas such as cold salads, soups, or as a filling for dumplings.
Trash or Treasure? Fruit Peels!
Did you know that fruit peels pack a nutritional punch even greater than the fruit flesh itself? Do you typically peel your fruits before indulging? Many opt to discard the peel due to its texture or concerns about pesticide residue. However, you might be surprised to learn that these seemingly
Elisa L.

Elisa L.

32 likes

Ready to deepen your relationship and prayer life?
I am actively on the lookout for women who are eager to embark on a transformative journey through "Fervent," a powerful book that guides us in praying strategically. As I seek individuals ready to delve into the depths of prayer with intention and purpose, I invite you to join me on this e
Prospherr

Prospherr

7 likes

How to Read Hunger Games Series In One Day!
#apprecommendation #hungergames #bookapp
lani 🎀

lani 🎀

1 like

A hand holds open a Bible journal with handwritten notes and highlights, featuring the text "BIBLE JOURNAL with me! Psalms 38-42" overlaid. A laptop and colorful pens are visible in the background, suggesting a study session.
An open Bible journal displays Psalms 37-38 with highlighted verses and handwritten notes. Key phrases like "faithful ness," "God is my rescue," and "Turn away from evil" are visible, along with a green-painted fingernail pointing to the text.
An open Bible journal shows Psalm 38 with extensive highlighting and handwritten annotations. Notes include "David feels the Weight of conviction," "guilt affects every part of David," and "healing begins with honesty," alongside the biblical text.
Bible Notes 📖 | Psalms 38-42
Bible notes 📖 | Psalms 38–42 These chapters are raw. They’re honest. They’re full of pain, repentance, and hope. Psalm 38 begins in brokenness, and Psalm 42 ends in holy longing. 💔 When David felt the weight of sin, he cried out. 🕊️ When he felt forgotten, he clung to God’s presence. ❤️‍🔥 And
jazz_whit

jazz_whit

223 likes

A hand holds two perfume bottles: Lattafa Eclaire and Khadlaj Cream Velvet, both in light brown and beige tones with gold accents. The image has an 'OOTD' overlay with sparkling star graphics, highlighting a gourmand fragrance layering combination.
Vanilla cupcake-For the gourmand girlies🧁🍨🤎
✨Eclaire + Cream Velvet✨ #gourmandfragrance #vanillaperfume #fragranceaddict #scentlayeringcombos #layeringperfume
Navy♡︎ SAHM Scent Diaries✨

Navy♡︎ SAHM Scent Diaries✨

52 likes

Consumer Reporting Agencies
Understanding consumer credit reporting agencies like Equifax, Experian, and TransUnion is crucial. We delve into their role in helping support fair consumer reporting, including accuracy, confidentiality, and the proper use of your information. #CreditReport #ConsumerRights #CreditEducation
Lemon8er

Lemon8er

3 likes

Grief Is A Journey
Grief is a profound and deeply personal journey that can feel isolating and overwhelming. Yet, the Bible offers us comfort and hope through its teachings. Here’s an inspiring reflection on grief grounded in Scripture: ### Understanding Grief Through Scripture **1. Acknowledgment of Pain:**
Wolfgirl52

Wolfgirl52

5 likes

A Strings of Fate Excerpt
An excerpt from my book of poetry, Strings of Fate. Now available on Amazon, Kindle, KU, Kobo, and Barns & Noble 🖤 #bookrecommendations #author #soulmate #poetry #indieauthor
Author Frances

Author Frances

7 likes

A person in a white tank top and gray sweatpants sits on a wooden floor, holding a phone to take a picture, with a sunset visible through a large window. An overlay reads: 'That girl podcasts ✨️ you will love ✨️'.
A podcast page for 'Anything Goes with Emma Chamberlain' is displayed, featuring a black and white cartoon cover image of a person's head and the podcast title. The description highlights its raw, intimate, and entertaining nature.
A podcast page for 'On Purpose with Jay Shetty' shows a cover image of Jay Shetty and the podcast title. The description states the podcast aims to make wisdom go viral through insightful conversations.
That girl podcasts ✨️ you will love ✨️
#lemon8tainment #myplaylist
Emma Taylor

Emma Taylor

23 likes

Humanize your AI generated content
We can humanize our AI generated content by fixing these 4 things #ai #chatgpt #aitoolsforbusiness #aitools
Rider

Rider

26 likes

Love and Art
#crafts #vase #memories
Freyja’ M

Freyja’ M

44 likes

Rotel dip
Believe it or not rotelle dip is a healthy choice of eating Rotel dip Rotel(any kind of your choice) Ground beef 1 pound Any sausage of your choice 1/2 pound Velveeta cheese Queso cheese Green onion Parsley 1/2 cream cheese Chips of your choice #rotel #latedinner #healthyrecipes
Jesscookinitup

Jesscookinitup

344 likes

Quotes i live by as a college student ⭐️📣
There are many times throughout college that I think back on quotes.m to help me gain motivation. I soon realized I didn’t have very many quotes that inspire me anymore, so I found some on BeFreed. BeFreed is the #1 smart reading app that condenses new nonfiction into: • 40 min deep dives
Naomilily

Naomilily

4 likes

Tropical Milkweed: Butterfly Magnet w/ a Dark Side
Butterfly lovers, this is a must-watch! Discover the controversy surrounding tropical milkweed and how it affects monarch migration. Tropical milkweed (Asclepias curassavica) is a popular garden plant known for its vibrant flowers and ability to attract butterflies, particularly monarchs. Howeve
Learn With Me

Learn With Me

1 like

Steven king
I’ve had this book on my TBR showed it a few times but now I’m finally able to get into it. I had to take a break from my other book “Haunting of Aderline” so I read a short story and now gonna start this and go back and forth between my two reads. #horrorbooks #stevenking #horror #bookworms
Officalcozyhome

Officalcozyhome

24 likes

See more