#3 Python Tutorial for Beginners | String in Python | Formatted String

Veröffentlicht am: 24 November 2019
auf dem Kanal: Rohan Paris
9
1

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)


Auf dieser Seite können Sie das Online-Video #3 Python Tutorial for Beginners | String in Python | Formatted String mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Rohan Paris 24 November 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 9 Mal angesehen und es wurde von 1 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!