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)
Nesta página do site você pode assistir ao vídeo on-line #3 Python Tutorial for Beginners | String in Python | Formatted String duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Rohan Paris 24 Novembro 2019, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 9 vezes e gostou 1 espectadores. Boa visualização!