1. ART INTEGRATED PROJECT
ON STRINGS
COMPUTER SCIENCE
By: Tapaswini Panigrahi
Class: 12
Sec: B
Roll no. :20
Submitted to: Chinmayee
sir
2. INTRODUCTION TO STRINGS IN PYTHON
In Python, strings are an essential data type used to represent textual
data. A string is a sequence of characters enclosed in single quotes
('') or double quotes (""). It is a versatile and widely used data type
that allows programmers to manipulate and work with text
effectively. Strings in Python are immutable, meaning they cannot be
changed once created. They provide a convenient way to store and
manipulate textual information such as names, addresses, messages,
and more. Understanding how to work with strings is crucial for
various tasks, including data processing, input validation, text
analysis, and generating output. In this presentation, we will explore
the fundamentals of strings in Python, including their creation,
manipulation, and common operations.
3. DEFINITION OF STRINGS
In programming, a string is a data type that represents a sequence of
characters. It is a fundamental concept used to store and manipulate
textual data. In Python, strings are enclosed in either single quotes (“)
or double quotes (“ ”) and can include letters, numbers, symbols, and
spaces.
4. IMPORTANCE OF STRINGS IN
PROGRAMMING
Strings play a vital role in programming and are widely used in various
applications. Here are some key reasons why strings are important in
programming:
Text Representation: Strings provide a way to represent and manipulate
textual information such as names, addresses, messages, file paths, and
more. They allow programmers to work with human-readable data
effectively.
Input and Output Handling: Strings are essential for handling user input and
displaying output in programs. They enable the interaction between users
and software by accepting and processing text-based inputs and generating
meaningful responses.
Text Processing and Manipulation: Strings offer a wide range of operations
and methods to process and manipulate text data. These include operations
like concatenation, slicing, searching, replacing, and formatting. String
5. STRING LITERALS
SINGLE AND DOUBLE QUOTES
Single Quotation Mark
Represented as ‘ ‘
Single quotes for anything that behaves like an
Identifier.
Single quotes are used for regular expressions,
dict keys or SQL.
Eg. ‘We “welcome” you.’
Double Quotation Mark
Represented as ” “
Double quotes generally we used for text.
Double quotes are used for string
representation.
Eg. “Hello it’s me.”
6. UNDERSTANDING MUTABLE AND
IMMUTABLE IN PYTHON
In the programming world, understanding the concepts of mutability
and immutability is crucial, especially when working with Python.
Python, being a dynamically-typed language, allows us to manipulate
objects and change their state during program execution. However,
not all objects in Python behave in the same way when it comes to
modification. Some objects can be altered, while others remain
constant once created. This fundamental distinction between mutable
and immutable objects forms the cornerstone of Python’s design
philosophy. By comprehending the concepts of mutability and
immutability, developers can write more efficient, reliable, and bug-
free code. In this article, we will explore the concept of mutability and
immutability in Python, understand their differences, and examine
their implications in practical programming scenarios
7. IS STRING IMMUTABLE
•Yes, string is immutable data type . The content of
string once assigned cannot be altered than
•Trying to alter string content may lead an error.
9. REPETITION
•Repetition as it name implies repreat the given string
•Asterisk (‘*’) is used as repetition operator.
10. MEMBERSHIP
•Membership operation refers to checking a string or character
is part or subpart of an existing string or not
•Python uses ‘in’ and ‘not in’ as membership operator.
•‘in’ returns true if the first string or character appears as
substring in the second string.
•‘not in’ returns true is the first string or character does not
appears as substring in the second string.
11. SLICING
•Extracting a specific part of string or substring is called slicing
•Subset occurred after slicing contains contiguous elements
•Slicing is done using index range
•End index is always excluded in resultant substring.
•Negative index can also be used for slicing.
13. Method Description
capitalize() Converts the first character to upper case
casefold() Converts string into lower case
center() Returns a centered string
count() Returns the number of times a specified value occurs in a
string
encode() Returns an encoded version of the string
endswith() Returns true if the string ends with the specified value
expandtabs() Sets the tab size of the string
find() Searches the string for a specified value and returns the
position of where it was found
format() Formats specified values in a string
format_map() Formats specified values in a string
index() Searches the string for a specified value and returns the
position of where it was found
PYTHON STRING METHODS
14. STRING LENGTH
USING THE LEN() FUNCTION
len() is a built-in function in python. You can use the len() to get the
length of the given string, array, list, tuple, dictionary, etc. You can
use len function to optimize the performance of the program. The
number of elements stored in the object is never calculated, so len
helps provide the number of elements
len() is a built-in function in python.You can use the len() to get the
length of the given string, array, list, tuple, dictionary, etc.
Value: the given value you want the length of.
Return value a return an integer value i.e. the length of the given
string, or array, or list, or collections.
15. PYTHON STRING COMPARISON
OPERATORS
In python language, we can compare two strings such as identifying whether the
two strings are equivalent to each other or not, or even which string is greater
or smaller than each other. Let us check some of the string comparison
operators used for this purpose below:
==: This operator checks whether two strings are equal.
!=: This operator checks whether two strings are not equal.
<: This operator checks whether the string on the left side is smaller than the
string on the right side.
<=: This operator checks whether the string on the left side is smaller or equal
to the string on the right side.
>: This operator checks whether the string on the left side is greater than the
string on the right side.
>=: This operator checks whether the string on the left side is greater than the
string on the right side.
16. PYTHON OUTPUT FORMATTING
In this tutorial, we will learn to format the output. Formatting and output
refer to presenting the output of a program. We can format the output in the
human-readable form or write the data into a file and some other specified
form. Sometimes we need to control the coming output so we can format it
according to our requirements. Users can handle strings by using string
slicing and concatenation operations to create any layout.
There are various ways to format output.
•We can use the f string method to format the string literals.
•The format() method of strings helps a user create a fancier output.
•We can also perform the string concatenation operations to create any layout
we want. The string class also has some methods that perform useful
operations for padding strings to given column width.
17. IMPORTANCE OF STRINGS IN REAL-
WORLD APPLICATIONS
String matching strategies or algorithms provide key role in various
real world problems or applications. A few of its imperative
applications are Spell Checkers, Spam Filters, Intrusion Detection
System, Search Engines, Plagiarism Detection, Bioinformatics, Digital
Forensics and Information Retrieval Systems etc.