PYTHON Module 2
Split method • Extracts the individual words separated by spaces, tabs(t) and new lines(n)
Cleaning Up Strings • Using for and in command it is possible to search for certain unwanted characters in strings and remove them • Then a new string can be created using the concatenation operator.
Example • Cleaned string with no punctuations.
Formatting strings using placeholders • Place holder is a facility in Python to create an empty space to store a value there later. • Using this feature, Python allows us to insert any value/string during the run time of the program.
Example
Formatting strings using placeholders
Output(s)
Other examples
Output(s)
Other examples • Many other examples found in the book… • TRY THEM.
TUPLE • It is a complex variable consisting of more than one value. • They are entered inside braces and separated by commas as follows.
Examples
TUPLE • It is possible to access a particular location within any Tuple. • … using Indexing as follows: Tuple Name[index #]
Example
TUPLE • Just like strings, Tuples are immutable too. • Once Python creates a tuple within its memory, it does not vary its contents later on.
Example
TUPLE • While working on real time data, it is sometimes necessary to initially create a tuple with a single value within it. • Such tuples are created as follows: • Tuple_name = (value,)
Example
Example • Note: Without the comma, the type would be string and not tuple.
TUPLE Assignment • Python supports Tuple packing & Tuple unpacking • Tuple packing is done as follows: • Tuple_name = (value1, “value 2” , value 3,)
TUPLE Packing
TUPLE Unpacking • Tuple unpacking is the process of storing the variables within a Tuple separately as follows: • (V1, V2, V3) = Tuple_name
TUPLE Unpacking

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