Strings in Python

WHAT IS THE STRING TYPE IN PYTHON?

STRINGS in python are arrays of bytes representing Unicode characters, in python syntax string is represented by enclosing characters in single or double quotes for one liner statement. And Multiline strings are represented by enclosing it in three double or three single quotes.

Example Code
a=โ€™Hello Worldโ€™
print(a)
b=โ€Hello Worldโ€
print(b)
c=โ€โ€โ€This is multiline
string statement!โ€โ€โ€
print(c)
d=โ€โ€™This is multiline
string statement!โ€โ€™
print(d)
print(a[0],a[1])
  • โ€˜Hello Worldโ€™ is the same as โ€œHello Worldโ€.
  • Three single quotes or three double quotes are used for multiline string statements.
  • Square brackets can be used to access elements of the string, the index of the first character starts from 0.
Output
Hello World
Hello World
This is multiline
string statement!
This is multiline
string statement!
H e

Posted

in

Tags:

Comments

Leave a Reply