String Operations in Python. |print all letters appear in two words|
String contains the slicing operator and the slicing with the stepsize parameter is used to obtain the subset of string. It also has basic concatination " + " in and repeatation " * ".
String Slicing Operators
The slicing operator return a subset of string called slice by specifying two indexes start and end.
Example:
output:
String Slicing with step size
If the programmer select every second character from string. This can be done by using step-size. We need to add third parameter as step-size.
Example:
output:
Some more Complex examples:
output:
The Plus(+) operators
The + operator is concatination operation is used to join to string.
Example:
output:
The Repeatation operators(*)
The multiplication (*) operator is used to concatinate the same string multiple times. It is also called as Repeatation operators.
Example:
output:
In or Not In operator
Both operator "in" and "not in" are used to check weather a string or substring present in another string.
Example:
output:
Write a program to print all the letters from word1 also appear in word2.
output:
Comments
Post a Comment