1) Strings :
They are contiguous set of characters represented in quotation marks.
Single quotes or Double quotes can be used
e.g. name1 = "Rohan"
name2 = 'Mohan'
print(name1)
print(name2)
Combination of single and double quote is not allowed. i.e a String in python should start and end with same quotation marks.
e.g. ERROR- name3 = "Sohan'
Subsets of strings can be represented using slice operator '[:]'
A slice operator takes two parameters seperated by colon
** [a:b] Here 'a' is the beginning position and 'b' is the end position of required string.
NOTE- [a:b] includes all characters starting from index position 'a' upto 'b' (i.e. character at position 'b' is not included)
** By default a string starts from position 0
e.g. str = "Elephant School"
print(str)
Elephant School
print(str[0])
E
print(str[3:11])
phant Sc
print(str[4:])
hant School
print(str[-4])
h
print(str[-9:-2])
nt Scho
print(str*2)
Elephant SchoolElephant School
** To clone a string-
str1= 'School of animals'
str2=str1[:]
print(str2)
2) Formatted Strings :
Use of formatted strings makes the visualization work easy for the code reader.
fname = "Rohan"
lname = "Paris"
msg = fname+ '['+lname+'] is a computer science student' # CONVENTIONAL WAY
print(msg)
msg2 = f'{fname} [{lname}] is a computer science student' # Using FORMATTED String
print(msg2)
On this page of the site you can watch the video online #3 Python Tutorial for Beginners | String in Python | Formatted String with a duration of hours minute second in good quality, which was uploaded by the user Rohan Paris 24 November 2019, share the link with friends and acquaintances, this video has already been watched 9 times on youtube and it was liked by 1 viewers. Enjoy your viewing!