• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Python » Python String startswith() Method
Next →
← Prev

Python String startswith() Method

By Dinesh Thakur

Python startswith() method returns True if the string starts with the specified prefix, otherwise False. Two parameters start, and the end is needed. The start is a starting index from which the index begins, and the end index is where searching stops.

The syntax of the method is: str.startswith(str, beg = 0,end = len(string));

Key Points :

• The function startwith() returns true if the string begins with the prefix we are searching for, and if it has no prefix, it returns false in this situation.
• This function’s parameter prefix is case-sensitive, indicating that Computer and computer are two distinct values.

We’ll be covering the following topics in this tutorial:

  • startswith() Parameters
  • Return Value from startswith()
  • startswith() With Tuple Prefix

startswith() Parameters

startswith() method takes a maximum of three parameters:

• Prefix:  This parameter is used to describe the prefix substring.
• start (optional): This is an optional parameter to set the matching boundary starting index.
• end (optional): It is also an optional parameter used to set the matching boundary’s ending index.

Return Value from startswith()

startswith() method returns a boolean.

• Returns True if the string begins with the prefix defined.
• Returns False if the string does not begin with the prefix defined.

Below is the python program to demonstrate the startswith() function:

str = "The Best Learning Resource for Online Education";
print (str.startswith( 'The' ))
print (str.startswith( 'for', 2, 40 ))
print (str.startswith( 'the', 2, 50 ))

When we run above the program, the outcome is as follows:

True
False
False

startswith() With Tuple Prefix

str = "We Love Python Programming"
output = str.startswith(('We', 'Programming'))
print(output)
output = str.startswith(('Python', 'Programming'), 8, 25)
print(output) 

When we run above the program, the outcome is as follows:

True
True

Below are several other functions that we can use to work with string in Python 3

capitalize()
center()
count()
decode()
encode()
endswith()
expandtabs()
find()
index()
isalnum()

isalpha()

isdecimal()
isdigit()
islower()
isnumeric()
isspace()
istitle()
isupper()
join()
ljust()

lower()

lstrip()
maketrans()
max()
min()
replace()
rfind()
rindex()
rjust()
rstrip()

split()

splitlines()
startswith()
strip()
swapcase()
title()
translate()
upper()
zfill()

You’ll also like:

  1. Python String maketrans() Method
  2. Python String split() Method
  3. Python String center() Method
  4. Python String ljust() Method
  5. Python String isnumeric() Method
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Python

Python Tutorials

  • Python - Home
  • Python - Features
  • Python - Installation
  • Python - Hello World
  • Python - Operators Types
  • Python - Data Types
  • Python - Variable Type
  • Python - Switch Case
  • Python - Line Structure
  • Python - String Variables
  • Python - Condition Statement
  • Python - if else Statement
  • Python - for-loop
  • Python - while loop
  • Python - Command Line
  • Python - Regular Expression

Python Collections Data Types

  • Python - List
  • Python - Sets
  • Python - Tuples
  • Python - Dictionary

Python Functions

  • Python - Functions
  • Python - String Functions
  • Python - Lambda Function
  • Python - map() Function

Python Object Oriented

  • Python - Oops Concepts
  • Python - File Handling
  • Python - Exception Handling
  • Python - Multithreading
  • Python - File I/O

Python Data Structure

  • Python - Linked List
  • Python - Bubble Sort
  • Python - Selection Sort
  • Python - Linear Search
  • Python - Binary Search

Python Programs

  • Python - Armstrong Number
  • Python - Leap Year Program
  • Python - Fibonacci Series
  • Python - Factorial Program

Other Links

  • Python - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW