#7 String Datatype in Python

“string” Data Type:

Sequence of collection of character.
The python string can be represented using:
               1) Single Quote (‘ ’)
               2) Double Quote (“ ”)
               3) Triple Quote (”” ’’’)





Accessing String Character’s

Each character of a string is accessed by using a unique index.
String support 2 types of Index:
1) Forward Index or Positive Index
2) Backward Index or Negative Index

String Index in Python


String Length, Concatenation and Slicing:

1) Length: len(string_varivable)   
2) String Concatenation: First string followed by second string.
3) String Slicing: Extracting particular portion of an string.


String Methods:

1) upper() : for converting a string into uppercase.
2) lower() : for converting a string into lowercase.
3) replace() : for replacing a portion of a string.
4) split() : for splitting a line into list of words.
5) strip() : removes blank spaces at the beginning and at the end of the string.
6) startswith()/endswith() 
7) find(string): returns 1st index position if found else returns -1.
8) count(): returns the count of a character or sub string.
9) capitalize(): capitalizes the first character of a string.

String Functions:

1) len() : returns the length of a string i.e number of characters
2) max() : returns the max character of a string based on ASCII value.
3) min() : returns the min character of a string.
4) ord() : returns the ASCII value.


String Special Characters:

1) ‘+’ String Concatenation
2) ‘*’ Repetition
3) ‘[]’ String Index
4) ‘[ : ]’ String Slicing
5) in (or) not in

Previous
Next Post »