Some of the commonly used built-in modules are:
For Example:
It contains some keys like Country, State, State Capital.
Their corresponding values are India, Rajastan and Jaipur respectively.
dict={'Country':'India','State':'Rajasthan','State Capital':'Jaipur'}
print dict[Country]
Output is India
What is type conversion in Python?
Type conversion refers to the conversion of one data type into another.
import numpy as np
arr = np.array([1, 3, 2, 4, 5])
print(arr.argsort()[-3:][::-1])
How to display the contents of text file in reverse order?
Eg: reversed(list(open(“file-name”,”r”))):
print(line)
What is self in python?
Self is basically an instance or an object of a class, This is explicitly included as the first parameter in python. It also helps to differentiate between the methods and attributes of a class with local variables.
def file_lengthy(fname):
with open(fname) as f:
for i, I in enumerate(f):
pass return i + 1
print("Number of lines in the file:
",file_lengthy("test.txt"))