Strings in python

Strings:

A String is a sequence of Unicode characters that may be a combination of letters, numbers, and special symbols. To define a string in Python, you can enclose the string in matching single or double quotes:

>>>string1="I am enclosed in single quotes."
>>>string2="I am enclosed in double quotes."

>>>string3='it doesn't look good at all.'
>>>print(string3)
it doesn't look good at all.

 To know how the string indexing works in Python
>>>s="Hello Python"
String
String
To access the first character on the string you just created,type and enter the variable name s and the index 0 within square brackets like this:
>>>s[0] 
you will get output:
'H'
>>>first='banana'
>>>letter=fruit[1]

The second statement extracts the character at index position 1 from the first variable and assign it to the letter variable.

Example
Example
Getting the length of the string using len
>>>fruit='banana'
>>>len(fruit)

OUTPUT:
6
Translate »