0% found this document useful (0 votes)
45 views

Python New Theory Question

Python is a general purpose, high-level, interpreted, dynamically typed and object-oriented programming language. It has a simple syntax and is easy to learn. Python supports multiple domains like ML, AI and data science. It is an open source, platform independent language with rich libraries and is widely used by companies like Facebook, Google and Instagram.

Uploaded by

tabrej saiyed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Python New Theory Question

Python is a general purpose, high-level, interpreted, dynamically typed and object-oriented programming language. It has a simple syntax and is easy to learn. Python supports multiple domains like ML, AI and data science. It is an open source, platform independent language with rich libraries and is widely used by companies like Facebook, Google and Instagram.

Uploaded by

tabrej saiyed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

1. what is python?

1. python is genral purpose.


2. highlevel
3. interpreted
4. dynamically typed
5. easy to learn
6. object oriented programming language.

1.2 genral purpose mean - python support multiple domain like ML,AI,data science.

1.3 high level means- we dont need to declare which type of variable is that.

1.4 dynamically typed- because its high level.

2. features of python?

1. simple and easy to learn.


2. free and open source.
3. plateform independent
4. rich library support.
5. its portabl.
6. embded.
7. extensible

open source- you can implement if you are not satisfied with the content .

embeded - c and java source code use on python.

extensible - python source code use on others programming language.

3. application of python?

1. desktop application.
2. web application.
3. game devlopement.
4. ML
5. data science.

localhost:8888/notebooks/theory question for python interview.ipynb 1/24


6. AI

4. what is variable?

variable are use to store some value or data.

5. difrence between snake case and camel case?

snake case- can be easier to read bcz underscore( _ ) make it clear .

camel case- can be harder to read bcz lack of seperator make it difficult.

6. use of python?

1. facebook
2. google
3. instagram.
4. spotify

7. compare high level and low level?

1. high level

1. its less efficient.


2. simple to understand.
3. simple to debug.
4. simple to maintain.
5. its portable.
6. its plateform independent.
7. it need compilore or interpreter for translation.

2. low level ?

1. its more efficient.


2. difficult to understand.
3. difficult to debug.
4. complex to maintain.

localhost:8888/notebooks/theory question for python interview.ipynb 2/24


5. its not portable.
6. its machine dependent.
7. it need assembler for translation.

8. why its plateform independent?

1. it can run on various operating system.


2. if we have python code for window and we want to run this code on other plateform then we dont need
to change it .
3. we can run this code on any plateform.

9. compare compilor or interpreter ?

1. compilor

1. compilor take entire programme as input.


2. conditional statement execute faster .
3. memory requirment is more.
4. error are display after entire programme check.

2. interpreter

1. interpreter take single line instruction as input.


2. conditional statement execute slower.
3. memory requirement in less.
4. error are display for every single line.

10. rules to define a variable?

1. a variable name must start with alphabets and underscore( _ ).


2. variable name must contain alphanumeric value and underscore.
3. variable name are case sensitive.
4. we can not use python reserved keywords.

localhost:8888/notebooks/theory question for python interview.ipynb 3/24


11. what is conditional statement?

its a dicision making statement . when we want to execute a block of code based on particular condition .
ex. if, elif, else.

12. what is range?

its used to genrate a sequence of number.

13. what is local varibale and global varibale?

1. local - a variable which is declare inside a function then its called local varibale.
2. global - a variable which is declare outside a function then its called global varibale.

13. what is data type?

1. its define type of variable .


2. it define what type of data we are going to store in variable.

1. numeric: int ,float , complex


2. text: string
3. sequence : list ,tuple, range,set,frozenset
4. set : set , frozenset
5. boolean: True, False
6. mapping : dictionary

14. what is type casting ?

type casting method convert variable data type into certain data type. ex.- int to float, float to int.

localhost:8888/notebooks/theory question for python interview.ipynb 4/24


15. what is indexing and slicing?

1. indexing - its process of accessing specific element in a sequence . ex - a=[1,2,3,4,5]

a[2]=3

2. slicing - its used to access one or more character from string. ex - a=[1,2,3,4,5,6]

a[0:3] = 1,2,3

16. how do you write comments in python and why its


imporatant?

there are two ways to comment 1- single line comment by hash keyword(#)

2- multiline comment by triple quotes()

why its important

1. Increasing readability
2. Explaining the code to others
3. Understanding the code easily after a long-term
4. Including resources
5. Re-using the existing code

17. what do you mean by python literals?

Python literals are a data type and can hold any value type, such as strings, numbers, and more.

18. what are difrent ways to assign value to a variable?

The assignment operator, denoted by the “=” symbol,

19. which are the difrent ways to perform string formating


explain with example?
1 #1. f-string format

localhost:8888/notebooks/theory question for python interview.ipynb 5/24


2 '''
3 a=10
4 b=20
5 add = a+ b
6 print(f'addition of {a} and {b} is {add}')
7 '''
8 #2. dot format
9 '''
10 a=10
11 b=20
12 add = a+ b
13 print('addition of {} and {} is {}'.format(a,b,add))
14 '''

20. what are string function?

1. capitalize() - its used to convert first character of string in upper case and remaining aree to a lower
case.
2. upper() - its use to convert lower into upper case.
3. lower() - its use to convert upper into lower case.
4. title() - its use to convert first character of each string in upper case.
5. swapcase() - its use to convert upper into lower and lower into upper.
6. L-strip() - its use to remove all white leading spaces from string.
7. R-strip()- its use to remove all trailing spaces from string.
8. strip() - its remove bothe side spaces from string.
9. count() - its used to count occurance of character or word in string.
10. replace()- its uses to replace a word or character in string.
11. index() - it will return an index position number from string
12. find() - it will return an index position number from string.
13. split() - its used to convert string data type into list data type.
14. join() - it will join multiple string together.

21. types of operator?

1. comparison operator (< , >, ==, <= ,>=, !=)


2. logical operator ( and or not )
3. arthmatic operator ( +, - ,* ,/ )
4. assignment operator (+=, -=, *= ,/= )

22. what is list?

1. list is a colectionof multiple items.


2. list are mutable.

localhost:8888/notebooks/theory question for python interview.ipynb 6/24


3. list are enclosed in square bracket.
4. it allow you to store multiple data type value.

23. what are the function or method of list?

1. append - it will add one element in list.


2. extend - it will add multiple element in list .
3. insert - it will add element at specific position through index number.
4. remove - its used to remove a character or item from list.
5. pop - it will remove item from list through index number.
6. clear - it will remove all element from list .
7. copy - its used to copy the list.
8. sort - its used to sort the list.
9. sorted - its a built in function use for list and string.
10. reverse - its user to reverse a list or string.

24. what is list compression?

its easy and compact syntax for creating a list from a string and another list.

25. what is tuple ?

1. its immutabale.
2. orderd.
3. duplicates items are allowed.
4. tuple are enlosed in round brackets.
5. multiple data types.

26. function of tuple?

1. count - its used to count occurance of character or word from string.


2. index - it return an index position number.

localhost:8888/notebooks/theory question for python interview.ipynb 7/24


27. compare list and tuple?

1. list

1. list are muttable.


2. orderd.
3. duplicates items are allowed.
4. list are enclosed in square bracket.
5. list require more space.
6. mutiple data type .

2. tuple

1. tuple are imuttable.


2. orderd.
3. duplicates items are allowed.
4. tuple are enclosed in round bracket.
5. tuple require less space.
6. mutiple data type .

28. break , continue and pass?

1. break - its use to terminate loop.


2. continue - its used to skip the current iteration value.
3. pass - it execute nothing .

29. what is the use of loops ?

1. for loops - its used when number of iteration are allready known.
2. while loops - its used when number of iterations are unknown.

30. what is set?

1. its mutable.
2. unorderd.
3. duplicate items are not allowed.

localhost:8888/notebooks/theory question for python interview.ipynb 8/24


4. set are enclosed in curley brackets.
5. we can not perform indexing and slicing operation on it.

31. what are the set function?

1. add - itsused to add single element .


2. update - its used to add multiple lement.
3. union - the set that contain all the element from both set and duplicate remove..
4. remove - if the string is not present in set and after that we will remove string then it will show error.
5. discard -if the string is not present in set and after that we will remove string then it will show original
string.
6. pop - it will remove random items.
7. clear - it will remove all element.
8. intersection - set that contain simiarities between two or more set.
9. diffrence - set that contain diffrence between two or more set.
10. symmetric difrence - set that conatin difrent value and same will be delete.

32. what is dictionary?

1. its a collection of key and value pair.


2. its mutable.
3. orderd.
4. keys can not be duplicate.

33. function and methods of dictionary?

1. get - used to get value of specified key from dictionary.


2. keys - used to retrive all the keys from dictionary.
3. values- used to retrive all the values from dictionary
4. items - its used to return the list with all dictionary keys and values.
5. it update the specific item to dictionary.
6. pop - it will delete item from dictionary by using key.
7. clear - it will delete all item from dictionary.

34. what is set default?

its used to add element in dictionary.

localhost:8888/notebooks/theory question for python interview.ipynb 9/24


35. what is copy?

copy is used to copy the element.

36. what is function?

function is a block of code which only runs when its called.

37. what is recursive function?

when a function called itself is called recursive function.

38. what is lambda function?

1. its an anonymous function - a function without a name.


2. lambda function is defined by lambda keyword.

39. what is built in function?

a function whose functionality is predefined in python. then its called built in function.

40. what is module?

python module is python file with dot py extension. ex - variable , function , class

41. what is file handling?

1. a file contain collection of data and information.


2. data can be update.
3. file handling perform such operations. 1 create. , 2 read., 3 append. , 4 delete. ,

localhost:8888/notebooks/theory question for python interview.ipynb 10/24


42. what are the file handling operation?

1. write
2. read
3. append
4. delete

43. what is os module?

os module is desing for interacting with operating system.

44. what is web scrapping?

its the process of extracting meaningfull data or imformation from web pages.

45. what is exception handling in python?

it allow you to seperately error handling code from normal code.

46. what is error?

1. Errors are problems that occur in the program due to an illegal operation performed by the user or by
the fault of a programmer, due to which stop the normal flow of the program.

47. types of exception?

1.ArithmeticError.

2.AttributeError.

3.Exception.

4.ImportError.

5.IndexError.

6.KeyError.

localhost:8888/notebooks/theory question for python interview.ipynb 11/24


7.NameError.

48. what is oops?

its an object oriented programming language.

49. what is the need of oops?

1. oops help user to understand the code easily.


2. with the help of oops increases readability, maintainability and understandability.
3. every big software can be easily written and managed by using oops.

50. what are the main features of oops?

1. inheritance
2. polymorphisome.
3. encapsulation.
4. abstraction.

51. what is class?

1. its a collection of object or its a blue print of object.


2. class keyword is used to define a class.

52. what is object?

1. object is the instance of the class.


2. object means real world entity which has its specific property and function.

53. what is polymorphisom?

1. polymorphisom means many form .


2. same function name, but difrent way of work with different paramter.

localhost:8888/notebooks/theory question for python interview.ipynb 12/24


53. what is inheritance? and types of inheritance?

1. when one object is aquring all the properties and behaviour of super class then its called inheritance.

__types of inheritance

1. Single Inheritance – where a derived class acquires the members of a single super class.
2. Multi-level inheritance – a derived class d1 in inherited from base class base1, and d2 are inherited
from base2.
3. Hierarchical inheritance – from one base class you can inherit any number of child classes
4. Multiple inheritance – a derived class is inherited from more than one base class.

54. what is abstraction?

a concept that hiding all the internal details of an application and showing functionality to the user.

55. what is encapsulation?

1. its a process of wrapping of data into a single unit.


2. its used to restric an access of method or variable from outside the class.

56. what is genrators?

1. genrator allow us to create are own genrator.


2. genrator contain one or more yeild statement.then its called genrators.

57. what are decorators?

it allow users to add new functionality to an existing object without modifying its structure.

58. difrence between del and clear?

1. del is used to delete a variable.


2. clear is used to delete a list or string and showing empty list.

localhost:8888/notebooks/theory question for python interview.ipynb 13/24


59.difrence between pop and remove?

1. pop - remove last inserted item or based on given index position .


2. remove - its used to remove first occurance of specific element.

60. difrence between reverse and reversed?

1. reverse - can only reverse a list.


2. reversed- its a built in function can be used to reverse a list , tuple , string , dictionary.

61. all method of list, tuple ,set, dictionary?


1 1.list 2. tuple 3.set 4. dict
2 1. append 1.count 1. add 1. get
3 2. extend 2.index 2. update 2. keys
4 3. insert 3. union 3. values
5 4. remove 4. remove 4. items
6 5. pop 5. discard 5. update
7 6. clear 6. pop 6. pop
8 7. copy 7. clear 7. clear
9 8. sort 8. intersection
10 9. sorted 9. diffrence
11 10. reverse 10. symmetric difrence
12 ​

62. what is array?

1. arrays are the fundamental data structure and imprtant part of the most programming language.
2. in python they are a container which are able to store multiple item of same data type.

63. what is bootstrap?

1. bootstrap is a giant collection of handy and reusable bits of code written in html, css, javascript .
2. its also front end framework that enable devloper to build fully responsive website.

localhost:8888/notebooks/theory question for python interview.ipynb 14/24


64. why we can not use multiple inheritance in java?

1. reason is to prevent code ambiguity.


2. for ex class b extends a both classes have the same method display.
3. now java compilor can not decide which display method should inherit.
4. to preven this sitution multiple inheritance is not possible in java.

65. what is data structure?

1. data structure are the container that organize and group data according to type.
2. the main data structre are 1.list 2.tuple 3.set 4.dict

66. what is constructor?

1. constructore are genrally used for instantiating an object.


2. the task of constructor is to initialize data member of the class when an object is created.
3. in python init method is called constructor and is always called when object is created.

67. what is destructor in python?

1. destuctore are called when an object get destroyed.


2. in python destructor are not needed bcz python has garbage collector that handle memory
management automatically.
3. del method is called destructor.

68. What type of language is python? Programming or


scripting?

Python is capable of scripting, but in general sense, it is considered as a general-purpose programming


language.

69. What is the difference between .py and .pyc files?

The .py files are the python source code files. While the .pyc files contain the bytecode of the python files.

localhost:8888/notebooks/theory question for python interview.ipynb 15/24


70. What are Keywords in Python?

1. And
2. Or
3. Not
4. If
5. Elif
6. Else
7. For
8. While
9. Break
10. As
11. Def
12. Lambda
13. Pass
14. Return
15. True
16. False
17. Try
18. With
19. Assert
20. Class
21. Continue
22. Del
23. Except
24. Finally
25. From
26. Global

71. How is memory managed in Python?

1. Memory management in python is managed by Python private heap space. All Python objects and
data structures are located in a private heap. The programmer does not have access to this private
heap. The python interpreter takes care of this instead.
2. The allocation of heap space for Python objects is done by Python’s memory manager. The core API
gives access to some tools for the programmer to code.
3. Python also has an inbuilt garbage collector, which recycles all the unused memory and so that it can
be made available to the heap space.

localhost:8888/notebooks/theory question for python interview.ipynb 16/24


72. What is the difference between Python Arrays and lists?

1. Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data
type elements.
2. whereas lists can hold any data type elements.

73. What are python iterators?

Iterators are objects which can be traversed though or iterated upon.

74. What are docstrings in Python?

Docstrings are not actually comments, but, they are documentation strings. These docstrings are within
triple quotes. They are not assigned to any variable and therefore, at times, serve the purpose of
comments as well.

theory questiion given by sir?

75.why function is useful?

1. for code reusablity.


2. Using functions, we may avoid writing the same logic or code in software many times.

76. What is the difference between a function and a method?

methods

1. Methods are always defined within a class.


2. Methods are linked to the objects of the class in which they are defined.
3. A method cannot be invoked by calling its name alone.

localhost:8888/notebooks/theory question for python interview.ipynb 17/24


function

1. Classes are not required to define a function.


2. Functions are not defined within a class.
3. Functions can be invoked just by calling their names.

77. uses of inheritance?

1. for code reusability.


2. aquiring all the property of super class

78. How do you open a file in Python? c. What is the difference


between read(), readline(), and readlines() methods in Python?

1 f = open('file_name.txt','w')
2 f.write('nilesh mahaadu kharat')
3 f.close()

1. read() retrieves the entire content as a single string,


2. readline() reads one line at a time
3. readlines() returns a list containing all lines in the file.

78. What is a module in Python? b. How do you import a


module in Python? c. What are some built-in modules in
Python and what are they used for?

1. module is python file with dot py extension.


2. by using import keyword along with the desired module name.
3. built in modules in python
A. os module
B. random module
C. math module
D. time module
E. sys module
F. collections module
G. statistics module
4. uses of their

localhost:8888/notebooks/theory question for python interview.ipynb 18/24


A. OS module for interacting with the operating system.
B. Datetime module for working with dates and times.
C. Math module for mathematical operations.
D. Csv module for reading and writing CSV files.
E. JSON module for working with JSON data.
F. Urllib module for working with URLs.

79. What is the purpose of the try/except block in Python?

1. The try block lets you test a block of code for errors.
2. The except block lets you handle the error.
3. The else block lets you execute code when there is no error.

80. What is the difference between an exception and an error in


Python?

81. What is a regular expression in Python?

Regular expressions are a powerful language for matching text patterns.

82. What is the re module in Python and how is it used? c.


What are some common regular expression patterns used in
Python?

1. The re module provides a set of powerful regular expression facilities, which allows you to quickly
check whether a given string matches a given pattern (using the match function), or contains such a
pattern (using the search function).

83. What is the purpose of the self parameter in a class


method?

using the “self” we can access the attributes and methods of the class in Python.

84 . How do you define a decorator in Python?

by using @ symbol

localhost:8888/notebooks/theory question for python interview.ipynb 19/24


85. What is an API in Python and how is it used

Application Programming Interface, is a server that you can use to retrieve and send data to using code

86. Can you use a for loop to iterate over a dictionary in


Python?

yes we can use for loops for dict

87 . How do you prevent an infinite loop when using a while


loop in Python

The loop is executed until CTRL + C is pressed, but Python also has a break statement that we can use
directly in our code to stop this type of loop.

88.What are loop control statements in Python and how are


they used?

1. Loop control statements are used to change the flow of execution. These can be used if you wish to
skip an iteration or stop the execution.
2. The three types of loop control statements in python are break statement,
3. continue statement, and
4. pass statement.

89. How do you use the else clause with a for loop in Python?

1. Python allows the else keyword to be used with the for and while loops too.
2. The else block appears after the body of the loop.
3. The statements in the else block will be executed after all iterations are completed

90. What are some benefits of using list comprehensions in


Python?

1. redusing the size of code


2. easy and compact syntax

localhost:8888/notebooks/theory question for python interview.ipynb 20/24


91. What are keywords in Python and how are they used?

1. Python Keywords are some predefined and reserved words in Python that have special meanings.
2. Keywords are used to define the syntax of the coding.

92. What is the difference between a keyword and an identifier


in Python?

1. keywords are the reserve words which are predefined and have a special meaning in the language,
whereas
2. an identifier is a unique name assigned to a variable, function, class, etc.
3. there are three types of identifiers in python
A. public
B. private
C. protected

93. How many keywords are there in Python and what are
some of the most commonly used ones?

1. There are 35 keywords in Python


2. A few examples of commonly used Python keywords are: True, False, else, import, break, if, finally, is,
and global.

94. Can you use a keyword as a variable name in Python?

no we can not used keyword as variable name

95. What is the purpose of the pass keyword in Python?

1. The pass statement is used as a placeholder for future code.


2. When the pass statement is executed, nothing happens, but you avoid getting an error when empty
code is not allowed.
3. Empty code is not allowed in loops, function definitions, class definitions, or in if statements.

localhost:8888/notebooks/theory question for python interview.ipynb 21/24


96. What is the purpose of the del keyword in Python?

The del keyword is used to delete objects. In Python everything is an object, so the del keyword can also
be used to delete variables, lists, or parts of a list etc.

97. What is the purpose of the global keyword in Python?

making it accessible from anywhere within the program.

98. What is the purpose of the nonlocal keyword in Python?

non locals means global variable

1 ## 99. How do you check if a string is a Python keyword?


In [5]: 1 import keyword
2 keys = ["for", "elif", "elseif", "nikhil",
3 "assert", "shambhavi", "True", "False", "akshat", "akash", "break", "ashty"
4
5 for i in range(len(keys)):
6 if keyword.iskeyword(keys[i]):
7 print(keys[i] + " is python keyword")
8 else:
9 print(keys[i] + " is not a python keyword")

for is python keyword


elif is python keyword
elseif is not a python keyword
nikhil is not a python keyword
assert is python keyword
shambhavi is not a python keyword
True is python keyword
False is python keyword
akshat is not a python keyword
akash is not a python keyword
break is python keyword
ashty is not a python keyword
lambda is python keyword
suman is not a python keyword
try is python keyword
vaishnavi is not a python keyword

localhost:8888/notebooks/theory question for python interview.ipynb 22/24


100. How do you use the with keyword in Python and what is
its purpose?

with statement is used in file handling to make the code cleaner and much more readable

101. What is the difference between a shallow copy and a deep


copy of a list in Python?

1. Shallow Copy reflects changes made to the new/copied object in the original object.
2. Deep copy doesn't reflect changes made to the new/copied object in the original object

102. What are some common built-in functions in Python that


can be used with data types?

1. min
2. max
3. sum
4. pow
5. super
6. type
7. zip

103. What is the difference between a function call and a


function definition in Python?

1. function is a block of code that performs a specific task,


2. function call is an expression that invokes a function and executes the code in the function.

104. How do you access an attribute of an object in Python?

Python getattr() function is used to get the value of an object's attribute

localhost:8888/notebooks/theory question for python interview.ipynb 23/24


105. What is the difference between a class variable and an
instance variable in Python?

1. class variable - a variable which is declare inside the class is called class varibale
2. instance variale- a variable whis is declare inside the function with self keyword

106. How do you modify the attributes of an object in Python?


`

If you want your method to modify any attribute, you can pass its name as a string. You can then use
getattr() and setattr() to get and set the attribute.

In [ ]: 1 ​

In [ ]: 1 ​

localhost:8888/notebooks/theory question for python interview.ipynb 24/24

You might also like