Strings in Python
Strings in Python
BY-CHARLOTTE TULLY
INTRODUCTION:
• String is a collection of alphabets , words or other characters
• Python has a built-in string class named str.
• We use single quotes or double quotes to represent a string
in python.
• Strings literal are written by enclosing a sequence of
characters in single (‘Hello python world ‘) ,, double
quotes(“Hello python world”) or in triple quotes (’’’Hello
python world’’’).
WHAT ARE STRINGS?
In python , a consecutive sequence of characters , which
are enclosed or surrounded by single (‘ ‘), or double (“ ”)
quotes , is known as a string . This sequence of
UNICODE characters may include a letter , a number ,
special character , whitespace or a backlash.
Triple quotes are typically used for strings that span
multiple lines
For example: Fruits=‘Mango Apple Grapes’
CREATING STRINGS :
Strings are among the most popular data types in python .
We can create them by simply enclosing them by simply
enclosing characters in quotes (single , double , triple ).
Python creates single quotes same as the double quotes .
Sometimes , triple quotes can be used in python , but they
are generally used to represent multiline strings and doc
string . An empty string is a string that has 0 characters .
For example::
Str1=“Hello world”
Str2=“python programming”
EMPTY STRINGS :
For example:
Str=“hello world”
TRANSVERSING A STRING
• In this course, you learned about working with strings, which are objects that contain
sequences of character data. Processing character data is integral to programming. It is a
rare application that doesn’t need to manipulate strings to at least some extent.
• Python provides a rich set of operators, functions, and methods for working with strings.
You now know how to:
• Use operators with strings
• Access and extract portions of strings
• Use built-in Python functions with characters and strings
• Use methods to manipulate and modify string data