惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
C
Check Point Blog
IT之家
IT之家
Engineering at Meta
Engineering at Meta
A
About on SuperTechFans
J
Java Code Geeks
G
Google Developers Blog
博客园_首页
腾讯CDC
博客园 - Franky
F
Fortinet All Blogs
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
Last Week in AI
Last Week in AI
B
Blog RSS Feed
Microsoft Azure Blog
Microsoft Azure Blog
Recent Announcements
Recent Announcements
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
H
Help Net Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Python String Methods Explained Simply (Common Operations)
Shahrouz Nik · 2026-05-22 · via DEV Community

Shahrouz Nikseresht

Strings have many built-in methods for common tasks. These methods return new strings and do not change the original.

Basic methods for changing case

text = "hello python"

print(text.upper())   # HELLO PYTHON
print(text.lower())   # hello python
print(text.title())   # Hello Python
print(text.capitalize())  # Hello python

Enter fullscreen mode Exit fullscreen mode

Removing whitespace

messy = "  hello  "

print(messy.strip())   # "hello"
print(messy.lstrip())  # "hello  "
print(messy.rstrip())  # "  hello"

Enter fullscreen mode Exit fullscreen mode

Finding and replacing

sentence = "I like cats and cats like me"

print(sentence.find("cats"))     # 7 (first position)
print(sentence.replace("cats", "dogs"))  # I like dogs and dogs like me

Enter fullscreen mode Exit fullscreen mode

Checking content

email = "user@example.com"

print(email.startswith("user"))  # True
print(email.endswith(".com"))    # True
print("123".isdigit())           # True
print("abc".isalpha())           # True

Enter fullscreen mode Exit fullscreen mode

Splitting and joining

words = "apple,banana,cherry"

word_list = words.split(",")
print(word_list)  # ['apple', 'banana', 'cherry']

new_string = "-".join(word_list)
print(new_string)  # apple-banana-cherry

Enter fullscreen mode Exit fullscreen mode

Simple examples

Clean user input:

name = "  Alice  "
clean_name = name.strip().title()
print(clean_name)  # Alice

Enter fullscreen mode Exit fullscreen mode

Count occurrences (use count method):

text = "hello hello world"
print(text.count("hello"))  # 2

Enter fullscreen mode Exit fullscreen mode

Quick summary

  • Methods like .upper(), .lower(), .strip() for formatting.
  • .find(), .replace() for searching and changing.
  • .startswith(), .endswith(), .isdigit() for checks.
  • .split() and .join() for lists and strings.

Practice common string methods on text. They are essential for cleaning and processing strings in Python programs.