Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
Next article icon

Python String Methods – Set 1 (find, rfind, startwith, endwith, islower, isupper, lower, upper, swapcase & title)

Last Updated : 02 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Some of the string basics have been covered in the below articles:

Strings Part-1 
Strings Part-2 

The important string methods will be discussed in this article

1. find(“string”, beg, end) :- This function is used to find the position of the substring within a string. It takes three arguments:

  • substring: The string to search for.
  • beg (starting index, default = 0).
  • end (ending index, default = string length).

returns -1 if the substring is not found in the given range.
returns the first occurrence of the substring if found.

2. rfind(“string”, beg, end) :- This function has the similar working as find(), but it returns the position of the last occurrence of string.

Python
str = "geeksforgeeks is for geeks" s = "geeks"  # using find() to find first occurrence of s print ("The first occurrence of s is at : ", end="") print (str.find( s, 4) )  # using rfind() to find last occurrence of s print ("The last occurrence of s is at : ", end="") print ( str.rfind( s, 4) ) 

Output: 

The first occurrence of str2 is at : 8
The last occurrence of str2 is at : 21

Time complexity : O(n) 
Auxiliary Space : O(1)

3. startswith(“string”, beg, end) :- The purpose of this function is to return true if the function begins with mentioned string(prefix) else return false.
4. endswith(“string”, beg, end) :- The purpose of this function is to return true if the function ends with mentioned string(suffix) else return false.

Python
str = "geeks" s = "geeksforgeeksportal"  # using startswith() to find if str  # starts with s  if s.startswith(str):          print ("s begins with : " + str)  else : print ("s does not begin with : "+ str)   # using endswith() to find  # if str ends with s  if s.endswith(str):      print ("s ends with : " + str)  else :      print ("s does not end with : " + str)  

Output: 

str1 begins with : geeks
str1 does not end with : geeks

Time complexity : O(n) 
Auxiliary Space : O(1)

5. islower(“string”) :- This function returns true if all the letters in the string are lower cased, otherwise false.
6. isupper(“string”) :- This function returns true if all the letters in the string are upper cased, otherwise false.

Python
# Python code to demonstrate working of  # isupper() and islower() str = "GeeksforGeeks" str1 = "geeks"  # checking if all characters in str are upper cased if str.isupper() :     print ("All characters in str are upper cased") else :      print ("All characters in str are not upper cased")  # checking if all characters in str1 are lower cased if str1.islower() :     print ("All characters in str1 are lower cased") else :      print ("All characters in str1 are not lower cased") 

Output: 
 

All characters in str are not upper cased
All characters in str1 are lower cased

Time complexity : O(n) 
Auxiliary Space : O(1)

7. lower() :- This function returns the new string with all the letters converted into its lower case.
8. upper() :- This function returns the new string with all the letters converted into its upper case.
9. swapcase() :- This function is used to swap the cases of string i.e upper case is converted to lower case and vice versa.
10. title() :- This function converts the string to its title case i.e the first letter of every word of string is upper cased and else all are lower cased.

Python
str = "GeeksForGeeks is fOr GeeKs"  # Converting string into its lower case s1 = str.lower(); print (" lower case string : " + str1)  # Converting string into its upper case s2 = str.upper(); print (" upper case string : " + str2)  # Converting string into its swapped case s3 = str.swapcase(); print (" swap case string : " + str3)  # Converting string into its title case s4 = str.title(); print (" title case string : " + str4) 

Output: 

 The lower case converted string is : geeksforgeeks is for geeks
The upper case converted string is : GEEKSFORGEEKS IS FOR GEEKS
The swap case converted string is : gEEKSfORgEEKS IS FoR gEEkS
The title case converted string is : Geeksforgeeks Is For Geeks

Time complexity : O(n) 
Auxiliary Space : O(1)



Next Article
Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
author
kartik
Improve
Article Tags :
  • Python
  • School Programming
Practice Tags :
  • python

Similar Reads

  • isupper(), islower(), lower(), upper() in Python and their applications
    Python provides several built-in string methods to work with the case of characters. Among them, isupper(), islower(), upper() and lower() are commonly used for checking or converting character cases. In this article we will learn and explore these methods: 1. isupper() MethodThe isupper() method ch
    2 min read
  • Python | Pandas Series.str.lower(), upper() and title()
    Python is a great language for data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages, making importing and analyzing data much easier. Python has some inbuilt methods to convert a string into a lower, upper, or Camel case. But th
    4 min read
  • Python String Methods | Set 3 (strip, lstrip, rstrip, min, max, maketrans, translate, replace & expandtabs())
    Some of the string methods are covered in the below sets.String Methods Part- 1 String Methods Part- 2More methods are discussed in this article1. strip():- This method is used to delete all the leading and trailing characters mentioned in its argument.2. lstrip():- This method is used to delete all
    4 min read
  • Find the first repeated word in a string in Python using Dictionary
    We are given a string that may contain repeated words and the task is to find the first word that appears more than once. For example, in the string "Learn code learn fast", the word "learn" is the first repeated word. Let's understand different approaches to solve this problem using a dictionary. U
    3 min read
  • Regex in Python to put spaces between words starting with capital letters
    Given an array of characters, which is basically a sentence. However, there is no space between different words and the first letter of every word is in uppercase. You need to print this sentence after the following amendments: Put a single space between these words. Convert the uppercase letters to
    2 min read
  • Python - Ways to sort list of strings in case-insensitive manner
    Sorting strings in a case-insensitive manner ensures that uppercase and lowercase letters are treated equally during comparison. To do this we can use multiple methods like sorted(), str.casefold(), str.lower() and many more. For example we are given a list of string s = ["banana", "Apple", "cherry"
    2 min read
  • Conversion of whole String to uppercase or lowercase using STL in C++
    Given a string, convert the whole string to uppercase or lowercase using STL in C++. Examples: For uppercase conversionInput: s = "String"Output: s = "STRING" For lowercase conversionInput: s = "String"Output: s = "string" Functions used : transform : Performs a transformation on given array/string.
    1 min read
  • Is Python Case-Sensitive? Yes, Here's What You Need to Know
    Yes, Python differentiates between uppercase and lowercase characters, making it a case-sensitive programming language. This distinction means that Python treats identifiers such as variable, Variable, and VARIABLE as entirely separate entities. Understanding this case sensitivity is crucial for any
    2 min read
  • String lower() Method in Python
    lower() method in Python converts all uppercase letters in a string to their lowercase. This method does not alter non-letter characters (e.g., numbers, punctuation). Let's look at an example of lower() method: [GFGTABS] Python s = "HELLO, WORLD!" # Change all uppercase letters to lowercas
    3 min read
  • Capitalize Each String in a List of Strings in Python
    In Python, manipulating strings is a common task, and capitalizing each string in a list is a straightforward yet essential operation. This article explores some simple and commonly used methods to achieve this goal. Each method has its advantages and use cases, providing flexibility for different s
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences