Question Python
Question Python
Guido van Rossum is a Dutch programmer best The complete script of Python is written in the C
known as the creator of the Python programming Programming Language.
language.
4. How Python got its name? 13. What is Python used for?
When he began implementing Python, Guido van Python is commonly used for developing websites
Rossum was also reading the published scripts from and software, task automation, data analysis, and
“Monty Python's Flying Circus”, a BBC comedy data visualization.
series from the 1970s. Van Rossum thought he
needed a name that was short, unique, and slightly
mysterious, so he decided to call the language 14. What can you do with python?
Python. Data analysis, machine learning, web development,
automation, scripting, Software testing and
prototyping
5. Why Python is invented?
It was mainly developed for emphasis on code
readability, and its syntax allows programmers to 15. What is Python shell?
express concepts in fewer lines of code. Python shell is the interpreter that executes your
python programs, other pieces of python code or
simple commands.
6. Who is the mother of Python?
Python, sometimes written Pytho, presided at the 16. How to clear shell in python?
Delphic oracle, which existed in the cult center for We can simply use Ctrl + l to clear the screen.
its mother, Gaia, "Earth", Pytho being the place
name that was substituted for the earlier Krisa. 17. What is indentation in python?
Indentation refers to the spaces at the beginning of
a code line
7. What does Python run on?
Python is a cross-platform programming language, 18. What is indentation used for?
which means that it can run on multiple platforms Provides readers with a sense of continuity.
like Windows, macOS, Linux.
19. How many types of Indentation?
Three types of indentation are present.
8. How many types of Python language are there?
There are four main Python coding styles: 20. What are the three types of indentation?
imperative, functional, object-oriented, and Normal indents, 1st line Indentation and hanging
procedural. indents.
24. How do you show indent? 39. Which datatype is used to store a whole number?
Go to home and select line and paragraph spacing. Integer data type
Line spacing options at the bottom of the menu.
40. What is range of data type?
25. What is 0.5 indent? -32768 to +32767
Place the cursor at the start of a paragraph and hit
the tab key on your keyboard. 41. Which data types takes maximum bytes?
Maximum number of bytes that can be stored in a
26. What is normal indent size? VARCHAR
No smaller than the current point size.
42. What is tuple?
27. How do restart python shell? Tuple is an ordered set of values.
Press the f5 key on keyboard.
43. What are long data types?
28. What is the difference b/w python shell and Long datatype is 64-bit two’s complement integer.
interpreter?
The shell is where you write your code directly in 44. What are data units?
the CLI, whereas the interpreter is the program that Decimal unit such as KB, MB, GB used to express
will interpret your code and execute. size of data.
30. Is shell a syntax. 46. What are the operands that are permitted with
The shell is a command language interpreter logical operators in Python?
We have three different logical operators which are
31. What are Data types in Python? supported by python, and they are, logical AND,
A data type is a set of values and set of operation. logical OR & logical NOT.
32. Different data types in python? 47. What is the difference between “is” and “ == “ in
Mutable data Type (List, set, Dictionary) Python?
Immutable Data Type (Number, string, Tuples) == operator is used in python to check for value
equality of both the operands whereas is an
33. Which type of data type is python number? operator is used to express whether the two
It is immutable data type, which is used to store operands are pointing towards the same object or
numeric value. not.
34. Why we use Data types? 48. What does == mean in Python?
Because it ensures that data is collected in the == is a python comparison operator. It is mainly
preferred format & value of each property is as used to check whether the values of two operands
expected are equal or not.
35. What is the size of int data types? 49. What is operator precedence in Python?
Int & unsigned int types have size of four bytes. Operator precedence is a predetermined order
used to resolve the problem called multiple
36. Which data type is faster in python? operations at a single time.
Dictionaries is fast data types.
50. Which operator has the highest precedence in
37. Is array a data type? Python?
Array is a data types that represents a collection of () parentheses have the highest precedence in
elements. python.
51. Which operator has the lowest precedence Python? Lists are used to store multiple items in a single
Logical OR has the lowest precedence in python. variable. Lists are created using square brackets.
52. What is Floor Division Python? 62. What are characteristics of List?
The Floor Operator is used to make a division that List are ordered, mutable and, allow duplicate
results in the whole number adjusted to the left in members
the number line.
63. What methods are performed on List?
53. Is there a "not equal" operator in Python? There are many methods performed on list append,
Yes! We have Not equal operator in python, and it clear, copy, court, pop, remove, index, reverse etc.
is used to compare two operands and returns True
statement if they are Not equal, and False if they 64. What is the use of append method?
are Equal. It adds an element at the end of the list
54. What does <> mean in Python? 65. What is the used of index method?
!= or <> both symbols are used for expressing the It returns the index of the first element with the
not equal. specified value.
55. When programming in Python operators with the 66. What do you mean by traversing a list?
same precedence are evaluated in which manner? Traversing means to access each element of list
When two python operators have the same
precedence, you use associativity to determine the 67. What do you mean by Concatenation in list?
order. Almost all operators have associativity of left Concatenation of list means combining the two list.
to right.
68. What is difference between indexing and slicing?
56. How many types of operations are supported by By indexing we can extract only one element of list
the Python language? while by slicing we can fetch a Sub list from main
Python language supports the following types of list.
operations.
• Arithmetic operations 69. Define Tuple.
• Comparison (i.e. Rotational) operations A collection of ordered and immutable objects is
• Assignment operations known as a tuple
• Logical operations
• Bitwise operations 70. What methods are performed on tuple?
• Membership operations Count (), index ()
• Identity operations.
71. What is a nested tuple?
57. What do you mean by statement in Python? A tuple Inside another tuple is called a nested tuple.
A statement is an instruction that the Python
interpreter can execute. 72. What is difference b/w lists and tuples?
Lists are mutable and Tuples are immutable.
58. Explain Operators and Operands?
Operators are special symbols that represent 73. Explain the function len() in Tuple.
computations like addition and multiplication. The len() returns the no. of elements of the tuple.
values the operator uses are called Operands
74. How we Can remove list element?
59. How are comments written in a program? To remove a list element, you can use either the del
In Python, comment start with ‘#’ symbol. Anything statement or the remove method.
written after # in a line is ignored by interpreter.
75. What is the use of count() method in tuple?
60. Explain assigning values to variables in Python. It Returns the number of times a specified value
The equal sign (=) is used to assign values to occurs in a tuple.
variables.
76. Add a list of elements to a set.
61. What is List? Sample_set = {1, 2, 3}
Sample_List=[4,5] Only the Dictionary 's keys will exist in the returned
set.
77. Return a new set of identical items from two sets.
Set1 = {10, 20, 30} 91. What is function?
Set2 = {30, 40, 20} Functions are nothing but a group of related
Paint (set1. intersection (Set2)) statements that perform a specific task.
78. Get only unique items from two sets. 92. Difference between user-defined and built-in
Set1 = {10, 20, 30, 40, 50} functions.
Set2 = {30, 40, 50, 60, 70} • User-Defined Functions - these types of functions
Print (Set1.union (Set 2)) are defined by the user to perform any specific task
• Built-in Functions - These are pre-defined
79. Remove items from the set at once. functions in python.
Set1 ={10, 20, 30, 40, 50}
Set2.difference- update ({10, 20, 30}) 93. What keyword is used for defining a function and
Print(set1) write the syntax.
‘def’ keyword is used for defining a function.
80. What is a set? Syntax: def function_name(parameters)
A set is an unordered collection of unique objects.
Duplicate values are removed when any object is 94. What is Lambda function?
converted to set. Functions that are anonymous un-named function.
81. What is the difference between a subset and a 95. What is Recursive function?
proper Subset? Functions that calls itself is known as recursive.
A proper subset is a subset of a set, not equal to
itself. 96. What are the main advantages of function?
Main advantages of functions are
82. Check if a set is proper Subset. i) It avoids repetition and makes high degree of
We can check if a set is a proper subset of another. code reusing.
set using the ‘<’ operator. ii) It provides better modularity for your
application.
83. What is a dictionary?
Dictionary is a set of key Value pairs, with each pair 97. What is meant by scope of variable? Mention its
being Unique. types.
Scope of variable refers to the part of the program,
84. Are Dictionaries case-sensitive? where it is accessible. The two types of
Yes. dictionaries are Case-sensitive scopes - local scope and global scope.
107. Define keyworded arguments (**kwargs). 119. What is the mod symbol?
**kwargs: Receive multiple keyword arguments as Modulo is a math operation that finds the
a dictionary. remainder when one integer is divided by another.
131. The copy module uses the ___________________ 143. Define object?
protocol for shallow and deep copy. An object represents an entity in the real world that
The copy module uses the pickle protocol for can be distinctly identified.
shallow and deep copy.
144. What is used to create an object?
132. In which direction is the turtle module pointed by Constructor
default?
By default, the turtle is pointed towards the east 145. The assignment of more than one function to a
direction. particular operator is called
Operator overloading
133. Which Python module is used to parse dates in
almost any string format? 146. The class methods in python are:
dateutil module Static, bounded and unbounded methods.
134. Name of 5-packages of Python? 147. What are the methods which begin and end with
NumPy, pandas, Seaborn, Requests, Pillow. two underscore characters are called.
Special methods. (Special methods are
135. If you work with image data which package you automatically called during object creation)
must require in python?
If you work with image data, make sure to check 148. what is setattr() used for?
out the Pillow package. setattr(obj, name, valere) is used to set an
attribute. If attribute doesn’t exit, then it would be
136. Python package uses for drawing attractive created.
statistical graphics?
Seaborn is a high-level interface for drawing 149. getattr() used for?
attractive statistical graphics with just a few lines of getattr(obj, name) is used to get the attribute of an
code. object.
137. Which package uses If you work with tabular, time 150. What is the operator through which class members
series, or matrix data? are accessed?
If you work with tabular, time series, or matrix data, dot operator
pandas is your go-to Python package.
151. A class may contain:
138. what is class? Attribute, methods, properties, constructor and
instance attributes.
152. hasattr() is used for? An abstract clan is crated to declare a set of
hasattr checks if an attribute exists or not and methods that must be created in any child class
return True or False. build on top of this abstract class.
153. What is the syntax of hiding data in python. 165. What is the purpose of abstract methods?
_variablename Abstract methods force the child class to give the
implementation of these methods in them and the
154. Which feature of python disconnects objects within help us achieve abstraction on each subclass can
class from useless data to hide. irrelevant give its own implementation.
information from end user.
Data hiding 166. Write syntax to create an abstract class in python.
from abc impout ABC
155. State advantage of data hiding. Class <abstract_class_name>(ABC):
Makes application more secure & more robust.
Prevent Creation of links to Wrong data. 167. Define function overriding in Python.
If you want is override the parent class method,
156. Define method overriding in python. create a function in the child with the same name
It is an ability of any OOP language that allows a and no of parameter. It is called function overriding.
subclass or child close to prove a specific
implementation of a method that is already 168. How many except statements can a try-except
provided by one of its super class a parent class block have?
There has to be at least one except statement.
157. State condition when method in subclass is said to
override the method in superclass. 169. When will the else part of try-except-else be
When method in subclass has same name same executed?
parameter or signature and same section type The else part is executed when no exception occurs.
158. What determines that which version of an 170. Can one block of except statements handle multiple
overridden method will be execution exception?
The type of object which is being refered Each type of exception can be specified directly.
determines that which version of an overridden There is no need to put it in a list.
method will be executed.
171. When is the finally block executed?
159. How parent's method can be called within The finally block is always executed.
overridden method
Using class name 172. What happens when ‘1’ == 1 is executed?
Using supper() It simply evaluates to False and does not raise any
exception.
160. When feature of python defends access to specific
users in the application? 173. What will be the output of the following Python
Data Hiding code?
lst = [1, 2, 3]
161. How data hiding in python performed? lst[3]
It is performed using the double underscore(__) The snippet of code shown above throws an index
before done prefix. error. This is because the index of the list given in
the code, that is, 3 is out of range. The maximum
162. Which proves helps to build a large and index of this list is 2.
complicated programs.
Data abstraction 174. What will be the output of the following Python
code, if the time module has already been
163. How abstraction to implemented? imported?
Abstraction to implemented using a abstract class. 4 + '3'
The line of code shown above will result in a type
164. Why abstract class is created in Python? error. This is because the operand ‘+’ is not
supported when we combine the data types ‘int’
and ‘str’. Sine this is exactly what we have done in 185. Which of the following geometry managers are
the code shown above, a type error is thrown. available in Tkinter?
.grid()
175. What will be the output of the following Python
code? 186. Config() in python Tkinter are used for?
int('65.43') To change the property of the widget
The snippet of code shown above results in a value
error. This is because there is an invalid literal for 187. Creating lines are come in which type of thing?
int() with base 10: ’65.43’. Canvas
176. Which of the following is not a standard exception 188. For user entry data, which widget we use in
in Python? Tkinter?
NameError, IOError and ValueError are standard Text
exceptions in Python whereas Assignment error is
not a standard exception in Python. 189. For what purpose, the bg is used in the Tkinter
widget?
177. Syntax errors are also known as parsing errors. To change the background of the widget
Syntax errors are known as parsing errors. Syntax
errors are raised when there is a deviation from the 190. How we import Tkinter in the python program?
rules of a language. Hence the statement is true. import Tkinter, import Tkinter as t, from Tkinter
import *
178. _______________________ exceptions are raised
as a result of an error in opening a particular file. 191. Title() is used for
IOError exceptions are raised as a result of an error Give a title name to the window
in opening or closing a particular file.
192. What is Tk() in Tkinter python?
179. Which of the following blocks will be executed It is a widget, function, constructor
whether an exception is thrown or not?
The statements in the finally block will always be 193. What is work of turtle.shape() function in Python?
executed, whether an exception is thrown or not. This function is used to set the turtle shape to
This clause is used to close the resources used in a shape with a given name or, if the name is not
code. given, return the name of the current shape.
180. Which of the following is an Arithmetic Exception? 194. Why is turtle graphics important?
Over Flow Error, Zero Division Error, Floating Point Turtle graphics are a great way to introduce kids to
Error coding. With short programs of just five to ten lines
of code, kids can create and modify while learning.
181. In python code, on encountering a syntax error, the 195. Why do you require to setup Python turtle screen?
_______________ does not execute the program. Because it uses tkinter for the underlying graphics,
During this initial step of program execution, also it needs a version of Python installed with Tk
known as parsing, the interpreter will look for any support.
incorrect syntax in python. on encounting a syntax
error, the Interpreter does not execute the 196. What is the command for Turtle installation?
program. pip install PythonTurtle
182. Which exception is raised when the index or 197. What is the use of Turtle() method?
subscript in a sequence is out of range? It Creates and returns a new turtle object.
IndexError
198. What is testing in python?
183. In python context, what does GUI stand for? Automated testing is the execution of your test plan
Graphical User Interface by a script instead of a human. Python already
comes with a set of tools and libraries.
184. Which of the following are valid Tkinter widgets?
button 199. What is the Python unit test?
Unit testing is a technique in which particular The unittest module produces three possible
module is tested to check by developer himself outcomes- OK, Failure and Error
whether there are any errors.
212. What are the Advance Testing Scenario?
200. What does test cases mean in python? Generate necessary input Execute the code, taking
A test case is a set of conditions which is used to the output. Match the output with an expected
determine whether a system under test works result.
correctly.