8 What are dataframes?
A dataframe refers to a two dimensional mutable data structure or data aligned in the tabular form with labeled axes(rows and column).
Syntax:
1 What are functions in Python?
A function is a block of code which is executed only when a call is made to the function. def keyword is used to define a particular function as shown below:
Output: Hi, Welcome to Intellipaat
7 What advantages do NumPy arrays offer over (nested) Python lists?
Nested Lists:
Numpy:
4 Differentiate between NumPy and SciPy?
NumPy | SciPy |
NumPy stands for Numerical Python | SciPy stands for Scientific Python |
It is used for efficient and general numeric computations on numerical data saved in arrays. E.g., sorting, indexing, reshaping, and more | This module is a collection of tools in Python used to perform operations such as integration, differentiation, and more |
There are some linear algebraic functions available in this module, but they are not full-fledged | Full-fledged algebraic functions are available in SciPy for algebraic computations |
4 Explain the use of the ‘with’ statement and its syntax?
In Python, using the ‘with’ statement, we can open a file and close it as soon as the block of code, where ‘with’ is used, exits. In this way, we can opt for not using the close() method.
6 Can you write an efficient code to count the number of capital letters in a file?
The normal solution for this problem statement would be as follows:
with open(SOME_LARGE_FILE) as countletter:
To make this code more efficient, the whole code block can be converted into a one-liner code using the feature called generator expression. With this, the equivalent code line of the above code block would be as follows:
count sum(1 for line in countletter for character in line if character.isupper())
2 How can you randomize the items of a list in place in Python?
This can be easily achieved by using the Shuffle() function from the random library as shown below:
Output: [‘Loves’,’He’ ,’To ,’In’, ‘Python’,’Code’]
5 What does *args and **kwargs mean?
Want to know about the real-world uses of Python? Read our detailed blog on Python Project ideas now.