PYTHON
Module 2
Strings
• It’s a series of characters (or numerals).
• Must be entered at the command prompt or in the
code within quotes.
Upper Command
• Upper command changes the case of the string
from lower to UPPER case as follows:
Examples for lower
• Upper command changes the case of the
string from UPPER to lower case as follows:
Capitalize()
• Capitalize() command changes the case of
only the 1st
letter of the string to UPPER to
lower case.
• Changes the first alphabet regardless of the
string regardless of the entire string’s case.
Examples for Capitalize()
• Changes the first alphabet regardless of the
string regardless of the entire string’s case.
Swapcase()
• Reverses the entire string’s individual
alphabet’s case.
enumerate()
• Lists the entire string’s elements one by one, along
with its index
• Does not work on its own
• Works along with the list command
Index
• Index is the numerical position of the alphabet inside
a string or the position of any element in a list.
• Helps us access a certain alphabet/character within a
string.
String - Length
• The length of a string shows the number of elements
present within it (including quotes).
• len command
Indexing & String length
• Indexing of a string(or list) starts with 0.
• Reason.
• To access the last element of a string, we must type…
• string_name[len – 1]
Example
‘+’ ve & ‘-’ve indices
• When a ‘+’ve index (starting with 0) is entered, it counts the
position of string element from L to R and returns the
corresponding alphabet.
‘+’ ve & ‘-’ve indices
• When a ‘-’ve index (starting with 1) is entered, it counts the
position of string element from R to L and returns the
corresponding alphabet.
Traversal
• It is the process of going from the very first element
of the string to its last element.
• Traversal can be done using while statement as
follows:
Example
Result
For Loop

Class 1 of Module 2 - Strings in Python Syllabus, VIT

  • 1.
  • 2.
    Strings • It’s aseries of characters (or numerals). • Must be entered at the command prompt or in the code within quotes.
  • 3.
    Upper Command • Uppercommand changes the case of the string from lower to UPPER case as follows:
  • 4.
    Examples for lower •Upper command changes the case of the string from UPPER to lower case as follows:
  • 5.
    Capitalize() • Capitalize() commandchanges the case of only the 1st letter of the string to UPPER to lower case. • Changes the first alphabet regardless of the string regardless of the entire string’s case.
  • 6.
    Examples for Capitalize() •Changes the first alphabet regardless of the string regardless of the entire string’s case.
  • 7.
    Swapcase() • Reverses theentire string’s individual alphabet’s case.
  • 8.
    enumerate() • Lists theentire string’s elements one by one, along with its index • Does not work on its own • Works along with the list command
  • 9.
    Index • Index isthe numerical position of the alphabet inside a string or the position of any element in a list. • Helps us access a certain alphabet/character within a string.
  • 10.
    String - Length •The length of a string shows the number of elements present within it (including quotes). • len command
  • 11.
    Indexing & Stringlength • Indexing of a string(or list) starts with 0. • Reason. • To access the last element of a string, we must type… • string_name[len – 1]
  • 12.
  • 13.
    ‘+’ ve &‘-’ve indices • When a ‘+’ve index (starting with 0) is entered, it counts the position of string element from L to R and returns the corresponding alphabet.
  • 14.
    ‘+’ ve &‘-’ve indices • When a ‘-’ve index (starting with 1) is entered, it counts the position of string element from R to L and returns the corresponding alphabet.
  • 15.
    Traversal • It isthe process of going from the very first element of the string to its last element. • Traversal can be done using while statement as follows:
  • 16.
  • 17.
  • 18.