Tuple, List, Dictionary, String Slice
String Slice:
str='I love python.'
>>>
print(str)
I love python.
>>>
print(str[0])
I
>>>
print(str[-1])
.
>>>
print(str[7:12])
pytho
>>>
print(str[7:13])
python
>>>
print(str[7:13]*5)
pythonpythonpythonpythonpython
>>>
print('hello '*5)
hello hello hello
hello hello
>>>
print(str[5:])
e python.
>>>
print(str[:5])
I lov
Tuple:
A tuple
is similar to the list as it also consists of a number of values separated by
commas and enclosed within parentheses. Value within tuple can not be changed.
>>> t=(10,'ten',11,'eleven')
>>> t
(10, 'ten', 11,
'eleven')
>>> print(t)
(10, 'ten', 11,
'eleven')
>>>
print(t[0])
10
>>>
print(t*2)
(10, 'ten', 11,
'eleven', 10, 'ten', 11, 'eleven')
>>>
print(t+t)
(10, 'ten', 11,
'eleven', 10, 'ten', 11, 'eleven')
>>> print(t[1:])
('ten', 11, 'eleven')
>>>
print(t[:1])
(10,)
>>>
print(t[:0])
()
>>>
print(t[:2])
(10, 'ten')
>>> t1=(10
'ten')
SyntaxError: invalid
syntax
>>> t1=(10,
'ten')
>>>
print(t[:1])
(10,)
>>>
print(t[1:])
('ten', 11, 'eleven')
>>>
print(t1[1:])
('ten',)
List:
It
is most versatile data type in Python.
It contains several type of data separated by comma.
>>>
l=['a',12,'b',15]
>>> l
['a', 12, 'b', 15]
Dictionary;
It
stores key-value pairs..
>>>
d={'a':'apple','b':'ball','c':'cat'}
>>> print(d['a'])
apple
>>>
print(d['a'])
apple
>>>
print(d['a'])
Type casting :
Explicit conversion of data type
>>>
n=int(23.2)+int(24.5)
>>>
n
47
Type Coercion:
Implicit conversion of data type
>>>
n=23+24.5
>>>
n
47.5
>>>
n=23.2+24
>>>
n
47.2
>>>
n=23+24
>>>
n
47
Good post. Extract the data from your needed website visit this link Web Data Scraper
ReplyDelete