As you can see, the first thing you learned was printing a simple sentence. This sentence was stored by Python as a string. However, instead of immediately printing strings out, we will explore the various things you can do to them.
#PythonTutorialForBeginners
#StringInPython
-----------------------------------------------------------------------------------------------------------------
first_name = 'ada'
last_name = "Lovelace"
print(first_name)
print(last_name)
#combining or concatenating string
full_name = first_name+" "+last_name
print(full_name)
#composing message using string variable
print("Hello,"+full_name+"!")
#title() method: begin with capital case
print(full_name.title())
#lower() method: converts string into lower case
print(full_name.lower())
#upper() method: converts string into upper case
print(full_name.upper())
#adding whitespace to string with tab "\t"
print("python")
print("\tPython")
#to add new line in string using "\n"
print("Language:\nPython\nC\nJava")
#you can also combine tab"\t" and "\n" in a single string
print("Language:\n\tPthon\n\tC\n\tJava")
#sytripping whitespace using strip()
language = ' Python '
print(language)
print(language.strip())
#removing extra space only from left side
print(language.lstrip())
#removing extra space only from right side
print(language.rstrip())
#accessing characters of a string
name= "kevin"
#display whole string
print(name)
#display first character of string
print(name[0])
#display third character
print(name[2])
#display the last character of string
print(name[-1])
#display second last character
print(name[-2])
#getting substring or slicing operation
str="PythonTutorial"
print(str)
#slicung 10th to last character
print("str[9:]: ",str[9:])
#slicing 3rd to 6th character
print("str[2:6]: ",str[2:6])
#slicing from start to 9th character
print("str[:9]: ",str[:9])
#slicing from 10th to second last character
print("str[9:-1]: ",str[9:-1])
#repetition of string-replication operator "*"
#repeating the string str by 3 times
print(str*3)
#check wether a string is present in another string or not
str1="welcome to python"
str2="welcome"
str3="xyz"
#str2 is in str1? TRUE
print(str2 in str1)
#str3 is in str1?FALSE
print(str3 in str1)
#str3 is not in str1? TRUE
print(str3 not in str1)
On this page of the site you can watch the video online Python Tutorial For Beginners 3 | String Manipulation with a duration of hours minute second in good quality, which was uploaded by the user Pranav anand 15 July 2020, share the link with friends and acquaintances, this video has already been watched 176 times on youtube and it was liked by 10 viewers. Enjoy your viewing!