You are on page 1of 3

5.

String Data Type(str)

str represent string data type.

A String is a sequence of characters enclosed within sigle quotes('') or double


quotes("") or triple quotes(''' ''',""" """)

ex:-
>>> s = 'scodeen'

10--->int
'scodeen'--->str
10.5--->float
ex:-
x = eval(input('First number:'))
y = eval(input('second number'))
print(x+y)

india nai tiobk batuibkeej ubd indian arngudfoaoddofhsdsoihfodhfvx jjsddgf

10--->int
'scodeen'--->str
10.5--->float

Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

Output:-

we can write print() function to display outputex:-


x = eval(input('First number:'))
y = eval(input('second number'))
print(x+y)

india nai tiobk batuibkeej ubd indian arngudfoaoddofhsdsoihfodhfvx jjsddgf

10--->int
'scodeen'--->str
10.5--->float

Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

Output:-

we can write print() function to display output


Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

10--->int
'scodeen'--->str
10.5--->float

Note:- But in python3 we have only input() method and eaw_input() method is not
available.

python 3 input() function behaviour exactly same as raw_input() method of py2 that
is every input value is treated as str type only.

Note:- raw_input function of python 2 is renamed as input() function in python3.

>>> type(s)
<class 'str'>
>>> type(s1)
<class 'str'>
>>>

by using single quotes or double quotes we can not represent multiline string
literals,so that for the multiline string we are using triple quotes.

def whtsapp_setting_dept(self):
a.self = a

''' This function is only use for


whts app setting department'''

slicing of strings.
slice means a piece.
[] operators is called slice operator,which can be used ti retrive parts of string.

In python strings folllows zero based index..

The index can be either +ve or -ve.

+ve index means forward direction from left to right.


-ve index means backward direction form right to left.

Rules:-
variable [start:end+1:steps]

>>> s = 'scodeen'
>>> s[0]
's'
>>> s[-1]
'n'
>>> s[6]
'n'
>>> s[0:3]
'sco'
>>> s[0::2]
'soen'
>>> s[-0]
's'
>>> s[0::]
'scodeen'
>>> s[0::2]
'soen'
>>> s[0:5:2]
'soe'
>>>

How to check the data type or module or class function?

ans:- dir()

string methods link:- https://www.w3schools.com/python/python_strings_methods.asp

You might also like