You are on page 1of 8

PYTHON STRINGS

Strings:

 Data Type.
 Sequence made up of one or more individual
characters where a character may be Letter,
Digit, Whitespace, or Any Other Symbol.

Character and String Representation:

 Character is also considered as a String in


python.
 We can enclose that in Single , Double or even
Triple quotes.
 A contiguous series of characters delimited by
single, double or triple quotes is called String.
 Example:
 Python has builtin class named ‘str’ which has
many useful features.

 We can simulaneously declare and define a


string by creating a variable of string type.
 Example:

Here, name and business are string variables.


And , “Raju” and “Real Estate” are strings.

Methods in String:

1. Indexing
2. Traversing
3. Concatenating
4. Appending
5. Multiplying

1. Indexing:

 Individual characters can be accessed using the


Subscript Operator ([])
 The Expression in brackets is called Index.
 The index of first character is 0
 The index of last character is n-1
 Where, n is length of the string.
 Example:

 If we try to exceed the bounds, IndexError will


be raised.
2. Traversing :

 A string can be traversed by accessing characters


from one index to another.
 It can be done using for loop.
 Example:
3. Concatenating:

 Concatenating means joining together.


 Joining two strings in python using ‘+’ operator
is known as string concatenation.
 Example:
4. Appending:

 Append means Add something at the end.


 Adding one string at the end of other string using
‘+’ operator is known as appending.
 Example:
5. Multiplying:

 Multiply the string using ‘*’ operator.


 Example:

You might also like