0% found this document useful (0 votes)
0 views15 pages

Python Developer Reference Questions_.

The document provides a comprehensive overview of Python programming, covering its features, applications, and fundamental concepts such as data types, control structures, functions, and object-oriented programming principles. It explains various built-in functions, operators, and error handling mechanisms, along with practical examples. Additionally, it discusses Python libraries and modules, emphasizing their importance in enhancing functionality and ease of use.

Uploaded by

the great King
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views15 pages

Python Developer Reference Questions_.

The document provides a comprehensive overview of Python programming, covering its features, applications, and fundamental concepts such as data types, control structures, functions, and object-oriented programming principles. It explains various built-in functions, operators, and error handling mechanisms, along with practical examples. Additionally, it discusses Python libraries and modules, emphasizing their importance in enhancing functionality and ease of use.

Uploaded by

the great King
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

1. What is Python?

Answer:
It is very simple and easy to learn.
It powerful, fast and secure.
It has very simple syntax.
It is powerful scripting language.
It can be run on different kind of platform like Windows, Mac, Linux, etc.

2. Why we use Python?


Answer:

Web Application

Software Development

Database GUI application

Scientific and Numeric Computing

Business Applications

Console Based Application

3. What are the applications developed using Python?


Answer:

Independent Platform

Object oriented

Flexible

Structure oriented

Portable

Simple

4. What are the features in Python?


Answer:

5. Is python, case sensitive language or not?


Answer:
Yes, python is a case sensitive language.

6. Why indentation is required in Python?


Answer:
Indentation is necessary for Python. It specifies a block of code. All code within loops,
classes, functions, etc. And also it is specified within the indented block. It is usually done by
using four space characters. If your code is not indented necessarily, it will not execute
accurately and will throw errors as well.

7. What is an iterator in Python?


Answer:
An iterator is an object which implements the iterator protocol.
It has a next() method which returns the next item in iteration, also iterators are objects
which can iterate objects like list, string, etc.

8. Why python is called an interpreted language?


Answer:
An interpreted language is any programming language which is not in machine level code
before run time. Therefore, python is an interpreted language.

9. What is comment?
Answer:
Python comments are statements that are not executed by the compiler.
It is not considered as a part of program.

10. What are the types of comments in Python?


Answer:
There are two types of comment in Python.

Single line comment

Multi line comment

11. What is single line comment?


Answer:
It is used to comment only one line.
Hash (#) is used for single line comment.

12. What is multiline comment?


Answer:
It is used to comment a block of code.
Triple quotes are used to multiline comment starts with ''' and ends with '''.

13. What is Keyword?


Answer:
The word which is predefined in the library is called keyword.
Keywords cannot use as a variable function name, class name or any other identifier.
14. What is Float function?
Answer:
Float () is a predefined function which is used to convert given data into float.

15. What is int() function?


Answer:
int() is a predefined function which is used to convert string into integer.

16. What is print in Python?


Answer:
It is a predefined function which is used to print data or information.

17. How can you convert a number to a string?


Answer:
In order to convert a number into a string, use the inbuilt function str().
If you want an octal or hexadecimal representation, use the inbuilt function oct() or hex().

18. What is Global variable?


Answer:
Variable are only referenced outside of that function known as global variable.

19. What is an Operator?


Answer:
It is a special symbol which is used to perform logical or mathematical operation on data or
variable.

20. What are the types of operator in Python?


Answer:

Arithmetic operators

Relational operators

Logical operators

Assignment operators

Bit-wise operators

Membership operators

Identity operators

21. What is Operand?


Answer:
It is a data or variable on which the operation is to be performed.
22. What is the use of // operator in Python?
Answer:
It is a Floor Division operator, which is used for dividing two operands with the result as a
quotient showing only digits before the decimal point.
For instance, 10//5 = 2 and 10.0//5.0 = 2.0

23. What is the purpose of relational operators in Python?


Answer:
The purpose of relational operators in Python is to compare values.

24. What are assignment operators in Python?


Answer:
The assignment operators in Python can help in combining all the arithmetic operators with
the assignment symbol.

25. What are membership operators?


Answer:
With the operators ‘in’ and ‘not in’.
Example:

print('me' in 'disappointment')

# o/p: True

26. How to differentiate Identity operators & Membership operators?


Answer:
Unlike membership operators, the identity operators compare the values to find out if they
have the same value or not.

27. What is import method?


Answer:
Import is a keyword, to access the script from another python file or module.

28. What is Input?


Answer:
Input () is a predefined function which is used to take user input in python.
Default user input is of type string.

29. What is “if statement”?


Answer:
If the condition is true its body will execute otherwise does not execute.

30. What is meant by for loop?


Answer:
For loop is used for sequential traversal.
It can be used to traverse string or array.
For loop is used to iterate over a sequence list, string, tuple, etc.
Iterating over a sequence is called traversal.

31. How to print the star (*) pattern without newline and space?
Answer:

for i in range(0, 20):

print('*', end="")

32. How will you create the following pattern using Python?
Answer:

**

***

****

Output:

for i in range(1,6):

for j in range(1,i+1):

print('*',end='')

print('\n')

33. What is list in Python?


Answer:
It is a collection of data of different data type.
It is used to store list of values.
A list is created by comma separated values between square brackets.

34. What is clear () function in list?


Answer:
This function is used to empty the list.

35. What are the built-in -type does python provides?


Answer:
Mutable:

List

Sets
Dictionaries

Immutable:

Strings

Tuples

Numbers

36. How can you count duplicate elements in a given list?


Answer:

list1 = [2, 3, 4, 3, 10, 3, 5, 6, 3]

e = list1.count(3)

print('The count of element: 3 is ', e)

37. What is meant by continue statement?


Answer:
It is used to skip the next statement and continue the loop. This mostly used with loop.

38. What is copy () function in list?


Answer:
This function copies the elements one list into another.

39. What is count function in list?


Answer:
This method counts the number of occurrence of particular item in a list.

40. What is docstring in Python?


Answer:
Documentation string or docstring is a multiline string used to document a specific code
segment.
The docstring should describe what the function or method does.

41. What is meant by extend in list?


Answer:
This function is used to join two lists.

42. What is append() function in list?


Answer:
It is used add the new element at the end of the list.

43. What is break statement?


Answer:
It terminates the current loop. Mostly used in for and while loop.
44. What is negative index in python?
Answer:
Python sequence can be index in positive and negative numbers.
For positive index, starts with 0 an soon. And negative index starts with (-1) in the last index.

45. What is meant by Pass Python?


Answer:
Pass means no operation python statement.

46. What is reverse function in list?


Answer:
This function reverses elements of the list.

47. What is pop () function in list?


Answer:
This function deletes the element of given index. It deletes last item if we do not pass index.

48. What is insert () function in list?


Answer:
Insert function is used to add new items into list at particular index.

49. What is meant by jump statement?


Answer:
It is used to transfer the control from one point to another point in the program.

50. What is sort function in list?


Answer:
This function sorts the list in ascending order or descending order.

51. What does len() do?


Answer:
It is used to determine the length of a string, a list, an array, etc.
Example:

S = "ABCD"

print(len(S))

52. What is meant by Tuple?


Answer:
It is a collection of data of different data types.
We cannot change the value of tuples.
A tuple is created using parentheses.

53. Explain the output of the following piece of code?


Answer:
tuple = (123, 'mani', 20, 'trichy')

tuple *= 2

print(tuple)

o/p:

(123, 'mani', 20, 'trichy', 123, 'mani', 20, 'trichy')

54. What does the following code give us?


Answer:

b = (1)

print(type(b))

b = (1,)

print(type(b))

55. What is difference between python Arrays and Lists?


Answer:

Arrays:

 Arrays in python can only contain same data type of elements.

 Homogeneous

 Consumes far less memory than lists

Lists:

 List in python can contain elements of different data types.

 Heterogeneous

 Consuming large memory

56. What will the following code output?


Answer:

word = 'abcdefghij'

word[:3] + word[3:]

The output is abcdefghij. The first slice gives us abc, the next gives us defghij.

57. What is the difference between List and Tuple?


Answer:
The difference between list and tuple is that list is mutable while tuple is not.
Tuple can be hashed, for example, as a key for dictionaries.

58. Describe about Slicing?


Answer:
A mechanism to select a range of items from sequence types like list, tuple, strings etc., is
known as slicing.

59. What are sets in python?


Answer:
It is an unordered collection of data of different data types.
Set does not contain duplicate elements. A set is created using curly brackets.

60. What is string in python?


Answer:
String is a collection of characters. It is created by using single quotes or double quotes.

61. How will you capitalize the first letter of string?


Answer:
In Python, capitalize() method capitalizes the first letter of a string. If the string already
consists of a capital letter at the beginning, then, it returns the original string.

62. How will you convert a string to all lowercase?


Answer:
To convert a string to lowercase, lower() function can be used.

S = "ABCD"

print(S.lower())

63. What if you want to toggle case for a Python string?


Answer:

print('SystECh'.swapcase())

o/p: sYSTecH

64. How does break, continue and pass works in python?


Answer:

 Break: Allows loop termination when some condition is met and the control is
transferred to the next statement.

 Continue: Allows skipping some part of a loop when some specific condition is met
and the control is transferred to the beginning of the loop.
 Pass: Used when you need some block of code syntactically, but you want to skip its
execution. This is basically a null operation. Nothing happens when this is executed.

65. What is function in python?


Answer:
It is a collection of statement that performs on a specific task.
It executes when it is called by its name.

66. What is function overriding?


Answer:
Function with same name and same parameters is called function overriding.

67. What is the split function used for?


Answer:
The split function breaks the string into shorter strings using the defined separator. It returns
the list of all the words present in the string.

68. What is meant by Parameters and Arguments?


Answer:
Parameters are the names listed in the function definition.
Arguments are the values passed to the function while invoking.

69. What are packing operators in Python? How to use them?


Answer:
The packing operators are used to collect multiple arguments in functions. They are known
as arbitrary arguments.

70. What is Local variable?


Answer:
If a variable is assigned anywhere within the function’s body its assumed to be local.

71. What are python libraries?


Answer:
Python libraries are a collection of python packages.
Some of majorly used python libraries are:

 NumPy

 Pandas

 Matplotlib

 scikit-learn

 PyTorch and many more.


72. What are modules in python?
Answer:
A module is a collection of statement in which we store functions, classes and variables.

73. What are some of the most commonly used built-in modules in Python?
Answer:
Python modules are the files having python code which can be functions, variables or
classes. These go by .py extension.
The most commonly available built-in modules are:

 os

 random

 datetime

 sys

 math

74. What is a lambda function?


Answer:
A lambda is an anonymous function. This function can have any number of parameters but
can have just one statement.
Example:

X = lambda a,b: a*b

print(X(2,4))

75. Does Python have Oops concepts?


Answer:
Python is an object-oriented programming language. This means that any program can be
solved in python by creating an object model. However, python can be treated as well as
structural language.

76. What is class in Python?


Answer:
It is a collection of data members and member’s functions.
Data members are the variable used inside class.
Member functions are the function used inside class.
It is also called user defined data type.

77. What is Parent class?


Answer:
The class which is inherited by another class is called parent or base class.
78. What is Child class?
Answer:
The class which inherits the property of another class is called child or sub or derived class.

79. What is self in python?


Answer:
Self is an instance or an object of a class. It helps to differentiate between the methods and
attributes of a class with local variables.

80. Does python support multiple inheritances?


Answer:
Multiple inheritances mean that a class can be derived from more than one parent classes.
Python does support multiple inheritances.

81. What are the class variables in python?


Answer:

 Private variable

 Public variable

 Protected variable

82. What is inheritance?


Answer:
The process of getting property of one class into another class is called inheritance.

83. What is init in python?


Answer:
__init__ is a method or constructor in python. This method is automatically called to allocate
memory when a new object is created. All classes have the __init__ method.

84. What is operator overloading?


Answer:
Operator overloading in python is a single operation based on the class (type) of operands.
Python operators work for built-in classes, the same operator behaves differently with
different types.

85. What is Encapsulation in python?


Answer:
Encapsulation is one of the fundamental concepts in object-oriented programming (OOP). It
describes the idea of covering data and the methods that work on data within one unit.

86. What is polymorphism in python?


Answer:
Polymorphism means the ability to take multiple forms. So, for instance, if the parent class
has a method named ABC then the child class also has a method with the same name ABC
having its own parameters and variables. Python allows polymorphism.

87. What is Data Abstraction?


Answer:
Abstraction means data hiding.
If we want to perform data hiding then it can be done by using __ prefix with variables then
they cannot be accessed outside that function.

88. What is file handling in python?


Answer:
File handling is a mechanism to store the data on the disk permanently. There are several
functions for creating reading, writing, updating and deleting files.

89. What is file operation in python?


Answer:

1. Opening of file.

2. Writing into a file.

3. Appending data into a file.

4. Reading from a file.

5. Closing of file.

90. What is read () function in file handling?


Answer:
read() function is used read content of a file.

91. How do you open a file for writing?


Answer:

file = open('filename.txt', 'w')

This opens the file in writing mode. You should close it once you’re done.

file.close()

92. Give example of sleep() function in Python


Answer:
Example of sleep() function in Python:

import time

print("Welcome to SYSTECH GROUP")

time.sleep(5)
print("This message will be printed after a wait of 5 seconds")

93. What are Reasons of Exception?


Answer:

 Mismatched input

 Defined Data type

94. What is try block?


Answer:
It is the place where actual code is written and exception occurs.

95. What is except block?


Answer:
Except block is intended to catch the error and handle the exception condition. We can have
multiline except blocks to handle different types of exception and perform different actions
when the exceptions occur.

96. What is finally block?


Answer:
This block executes either exception occurs or does not occurs.

97. Explain important Python errors?


Answer:
The important Python errors are:

1. Arithmetic Error

2. Import Error

3. Index Error

 Arithmetic Error: Acts as a base class for all arithmetic exceptions. It is raised for
errors in arithmetic operations.

 Import Error: Raised when you are trying to import a module which does not
present. This kind of exception occurs if you have made a typing mistake in the
module name or the module which is not present in the standard path.

 Index Error: Raised when you try to refer a sequence which is out of range.

98. What is the output of the following code?


Answer:

first = [1, 2, 3, 4, 5]

second = first
second.append(6)

print(first)

print(second)

o/p:

[1, 2, 3, 4, 5, 6]

[1, 2, 3, 4, 5, 6]

99. How a file is deleted in Python?


Answer:
The file can be deleted by either of these commands:

os.remove(filename)

os.unlink(filename)

100. What is difference between python and other programming languages?


Answer:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy