In this notebook, I will talk about basics of string and Literal in Python. Following notebook has been built using Python3.6
Let us start with Python string. String can be declared in Python using double quotes.
In [1]:
string = "I am John"
In [2]:
type(string)
Out[2]:
str
For literals, we have to use the single quotes.
In [3]:
literal = 'I am John'
In [4]:
type(literal)
Out[4]:
str
As we see both are string types.
In [5]:
literal==string
Out[5]:
True
In Python3+, string,literals and unicode literals are same.
In [6]:
u'I am John' == 'I am John' == "I am John"
Out[6]:
True
We can also verify that by looking at the size of each data type.
In [7]:
import sys
In [8]:
sys.getsizeof(u'I am John')
Out[8]:
58
In [9]:
sys.getsizeof('I am John')
Out[9]:
58
In [10]:
sys.getsizeof("I am John")
Out[10]:
58
Double quotes can be used inside single quotes
from Planet SciPy
read more
No comments:
Post a Comment