In this program – we are going to learn how can we complete string, print specific characters, print a range of the characters, print string multiple times (using * operator), print multiple stings by concatenating them etc.
Syntax to print string in different ways:
print (string) # printing complete string
print (string[i]) # printing ith element of string
print (string[i], string[j])# printing ith and jth elements
print (string[i:j]) # printing elements from ith index to jth index
print (string[i:]) # printing all elements from ith index
print (string * 2) # printing string two times
print (string1 + string2) # printing concatenated string1 & string2
Python code to print string characters
Here, we have two strings str1 and str2 and we are printing elements in the different ways.
Output
need an explanation for this answer? contact us directly to get an explanation for this answer