You are on page 1of 6

1. What makes python better than other languages?

Python is a high-level programming language (more user-friendly and independent of the


computer’s hardware architecture) and it’s core philosophy is about increased code
readability and a syntax that allows programmers to express concepts in few lines of code.
1. Simplicity
2. Large community of users
3. High demand supply ratio
4. Large number of frameworks
5. AI/ML

2. What is debugging? Explain the different types of errors.

Process of tracking errors in our code (bugs) is called debugging.

There are 3 kinds of error:-

1. Syntax errors
2. Run-time errors – error does not occur until program starts running. Error occurs when we
code an exceptional case or illegal statement. (10/0)
3. Semantic error –
Program will run but desired output will not be generated

3. What is a variable? Specify the rules for naming variables.

A variable is a name given to a memory allocation. It is the basic unit of storage in a program.

Rules for naming a variable –

1. Variable name must start with a letter or underscore, it cannot start with a number
2. A variable name can contain alpha-numeric characters and underscore. No special
characters are allowed.
3. Variable name are case-sensitive
4. Reserved keyword (built-in in python) cannot be used as variables

4. What are operators? Give their rule of precedence

Operators are special symbols that represent computation.

When more than one operator appears in an expression we use the rule of precedence which is
given by the acronym PEMDAS

1. Parenthesis
2. Exponential
3. Multiplication and Division
4. Addition
5. Subtraction
5. What are the different types of operators in python?

1. Arithmetic operators – used with numerical values to perform common mathematical operations

2. Assignment operators – Operators used to assign values to variables

3. Comparison operators – used to compare two values in python

4. Logical operators – Used to combine conditional statements

5. Identity operators - Identity operators are used to compare the objects, not if they are equal, but
if they are actually the same object, with the same memory location
Eg – is, is not

6. Membership operators – Used to check if a sequence belongs to a certain object or not (in and not
in)

7. Bitwise operators – used to compare binary numbers

6. What are comments? Why are they useful?

Comments are the description written in the source code contained in some special characters
so that they get ignored by the compiler while running the code.

Usage –

1. Code readability increases


2. Easier to edit code later

They are of two types – single line and multi line


7. Explain the break and continue statements with the help of flowchart

In Python, break and continue statements can alter the flow of a normal loop. Loops iterate over
a block of code until test expression is false, but sometimes we wish to terminate the current
iteration or even the whole loop without checking test expression. The break and continue
statements are used in these cases

1. Break statement
The break statement terminates the loop containing it. Control of the program flows to
the statement immediately after the body of the loop. If it is inside a nested loop (loop
inside another loop), break will terminate the innermost loop.

2. Continue statement
The continue statement is used to skip the rest of the code inside a loop for the current
iteration only. Loop does not terminate but continues on with the next iteration.
8. How many numerical types are available in python? Explain them.

•int (signed integers): They are often called just integers or ints. They are positive or negative
whole numbers with no decimal point. Integers in Python 3 are of unlimited size. Python 2 has
two integer types - int and long. There is no 'long integer' in Python 3 anymore.

•float (floating point real values) : Also called floats, they represent real numbers and are
written with a decimal point dividing the integer and fractional parts

•complex (complex numbers) : are of the form a + bJ, where a and b are floats and J (or j)
represents the square root of -1 (which is an imaginary number). The real part of the number is
a, and the imaginary part is b. Complex numbers are not used much in Python programming

9. What are lists? Give example

A list is an ordered set of values, where each value is identified by an index. The values that
make up a list are called its elements. Lists are similar to strings, which are ordered sets of
characters, except that the elements of a list can have any type. Lists and strings and other
things that behave like ordered sets are called sequences. Unlike strings, lists are mutable, which
means we can change their elements.

10. Differentiate between Aliasing and Cloning


11. Describe the relationship between string.join(string.split(song)) and song. Are they the same
for all strings? When would they be different? (song is a string)

They will not be same for all strings. This is because the list will be joined from from where it was
split i.e the space. Therefore each character will come twice. However in a string without any
spaces it would give same output.

12. Give differences between List, tuple and dictionary

https://www.geeksforgeeks.org/differences-and-applications-of-list-tuple-set-and-dictionary-in-
python/

13. What are dictionaries?

Python dictionary is an unordered collection of items. Each item of a


dictionary has a key/value pair.Dictionaries are optimized to retrieve
values when the key is known. These key-value pairs are not in order.
14. What is pickling and unpickling?

The pickle module implements binary protocols for serializing and de-serializing a
Python object structure. “Pickling” is the process whereby a Python object hierarchy is
converted into a byte stream, and “unpickling” is the inverse operation, whereby a byte
stream (from a binary file or bytes-like object) is converted back into an object hierarchy.
15. Scope of variable
16. Difference between print and return
17. Tell the different modes of opening a file in python

Read Only (‘r’) : Open text file for reading.

The handle is positioned at the beginning of the file.

If the file does not exists, raises I/O error.

This is also the default mode in which file is opened.

Read and Write (‘r+’) : Open the file for reading and writing.

The handle is positioned at the beginning of the file.

Raises I/O error if the file does not exists.

You might also like