#interviewQuestions : 0004
Is Python a Scripting Language?
Python is capable of scripting, but it is more than that. It is considered as a general-purpose programming language.
Is Python a Scripting Language?
Python is capable of scripting, but it is more than that. It is considered as a general-purpose programming language.
#interviewQuestions : 0005
Is Python interpreted or compiled?
A common question: “Is Python interpreted or compiled?” Usually, the asker has a simple model of the world in mind, and as is typical, the world is more complicated.
In the simple model of the world, “compile” means to convert a program in a high-level language into a binary executable full of machine code (CPU instructions). When you compile a C program, this is what happens. The result is a file that your operating system can run for you.
In the simple definition of “interpreted”, executing a program means reading the source code a line at a time, and doing what it says.
Compiling is a more general idea: take a program in one language (or form), and convert it into another language or form.
In Python, the source code is compiled into a much simpler form called bytecode. These are instructions similar in spirit to CPU instructions, but instead of being executed by the CPU, they are executed by software called a virtual machine.
So, if you can explain all this, then you can say its both a compiled and interpreted language.
But, if you want to give a simple and short answer, then say it is a interpreted language.
Is Python interpreted or compiled?
A common question: “Is Python interpreted or compiled?” Usually, the asker has a simple model of the world in mind, and as is typical, the world is more complicated.
In the simple model of the world, “compile” means to convert a program in a high-level language into a binary executable full of machine code (CPU instructions). When you compile a C program, this is what happens. The result is a file that your operating system can run for you.
In the simple definition of “interpreted”, executing a program means reading the source code a line at a time, and doing what it says.
Compiling is a more general idea: take a program in one language (or form), and convert it into another language or form.
In Python, the source code is compiled into a much simpler form called bytecode. These are instructions similar in spirit to CPU instructions, but instead of being executed by the CPU, they are executed by software called a virtual machine.
So, if you can explain all this, then you can say its both a compiled and interpreted language.
But, if you want to give a simple and short answer, then say it is a interpreted language.
Which is faster in performance while searching around a million records plus?
Anonymous Quiz
23%
List
10%
Set
24%
Dict
20%
Tuple
13%
All have the same performance
9%
See the answer
#interviewQuestions : 0006
What is pep 8?
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
PEP stands for Python Enhancement Proposal, and there are several of them. A PEP is a document that describes new features proposed for Python and documents aspects of Python, like design and style, for the community.
What is pep 8?
PEP 8, sometimes spelled PEP8 or PEP-8, is a document that provides guidelines and best practices on how to write Python code. It was written in 2001 by Guido van Rossum, Barry Warsaw, and Nick Coghlan. The primary focus of PEP 8 is to improve the readability and consistency of Python code.
PEP stands for Python Enhancement Proposal, and there are several of them. A PEP is a document that describes new features proposed for Python and documents aspects of Python, like design and style, for the community.
What is the output of this statement?
16//3+16//-3
16//3+16//-3
Anonymous Quiz
6%
1
51%
0
13%
-1
7%
True
13%
Invalid Statement
9%
Show the answer
#interviewQuestions : 0007
Q: What is the output of the following statement? Explain Why?
Q: Explain // and how it works?
Q: Explain Floor Division?
16//-3
Output: -6
// (Floor division)
It gives the floor value of the quotient produced by dividing the two operands. In other words, the floor division // rounds the result down to the nearest whole number.
print(x/y)
print(x//y)
Notice that we are using the same values for x and y operands. But the result is quite different between / and //.
When the result of floor division (//) is positive, it is as though the fractional portion is truncated off, leaving only the integer portion.
When the result is negative, the result is floored, i.e., rounded away from zero (towards negative infinity). In other words, rounded down to the next smallest (greater negative) integer.
Let us see some more examples.
print(float(x)//float(y)) # Notice the result will also be a float.
x = -13 # Notice the value of `x` is assigned by with a unary negation (`-`) operator
y = 3
print(x//y) # Notice the result.
# Instead of rounding up to 4 like in the case of a positive result, it round up to -5, the lesser value
x= -13.0 # We changed the type of `x` from int to float. No change in value.
print(x//y) # What will be the result.
Unlike the standard division (/), the result is not always a float. But when one of the operands is a float, then the result will also be a float.
Division by zero will yield in the same error as above.
Q: What is the output of the following statement? Explain Why?
Q: Explain // and how it works?
Q: Explain Floor Division?
16//-3
Output: -6
// (Floor division)
It gives the floor value of the quotient produced by dividing the two operands. In other words, the floor division // rounds the result down to the nearest whole number.
print(x/y)
print(x//y)
Notice that we are using the same values for x and y operands. But the result is quite different between / and //.
When the result of floor division (//) is positive, it is as though the fractional portion is truncated off, leaving only the integer portion.
When the result is negative, the result is floored, i.e., rounded away from zero (towards negative infinity). In other words, rounded down to the next smallest (greater negative) integer.
Let us see some more examples.
print(float(x)//float(y)) # Notice the result will also be a float.
x = -13 # Notice the value of `x` is assigned by with a unary negation (`-`) operator
y = 3
print(x//y) # Notice the result.
# Instead of rounding up to 4 like in the case of a positive result, it round up to -5, the lesser value
x= -13.0 # We changed the type of `x` from int to float. No change in value.
print(x//y) # What will be the result.
Unlike the standard division (/), the result is not always a float. But when one of the operands is a float, then the result will also be a float.
Division by zero will yield in the same error as above.
y, z = 10, 15;
b = c = 0;
b = y - y + z; y -= (y + z); #What is the value of b & y respectively? Please Explain?
b = c = 0;
b = y - y + z; y -= (y + z); #What is the value of b & y respectively? Please Explain?
Anonymous Quiz
19%
15, 15
46%
15, -15
10%
-15, 15
14%
Error
10%
Show me the answer
#interviewQuestions : 0008
Q: List.copy() does a shallow copy of the list, but when we check their id's they point to different address? Why?
A shallow copy means constructing a new collection object and then populating it with references to the child objects found in the original.
Hence, when you check their id's they both point to different address.
check out this code
L1 = 1, 2, 3, 4
# Using copy() to create a shallow copy
L2 = L1.copy()
print(id(L1), id(L2))
>>> 2763664559240 2763665433480
In the above result, address are different, they both point to different locations.
But, the elements will be pointing to the same objects in both the lists.
Check this code:
print(id(L10), id(L20))
>>> 140703554137856 140703554137856
See the result, the elements point to the same address in memory.
#list #collection #shallowCopy
Q: List.copy() does a shallow copy of the list, but when we check their id's they point to different address? Why?
A shallow copy means constructing a new collection object and then populating it with references to the child objects found in the original.
Hence, when you check their id's they both point to different address.
check out this code
L1 = 1, 2, 3, 4
# Using copy() to create a shallow copy
L2 = L1.copy()
print(id(L1), id(L2))
>>> 2763664559240 2763665433480
In the above result, address are different, they both point to different locations.
But, the elements will be pointing to the same objects in both the lists.
Check this code:
print(id(L10), id(L20))
>>> 140703554137856 140703554137856
See the result, the elements point to the same address in memory.
#list #collection #shallowCopy
What is the output of the following code (Python 3x). Explain why?
print (type (1/2))
print (type (1/2))
Anonymous Quiz
13%
class int
5%
class number
62%
class float
10%
class decimal
4%
none of the above
6%
Show me the answer
prefix = "hello"
print(prefix, "world!")
# What is the output of the above code? Hint: There is no space in these two words.
print(prefix, "world!")
# What is the output of the above code? Hint: There is no space in these two words.
Anonymous Quiz
45%
helloworld!
39%
hello world!
4%
world! hello
6%
world!hello
4%
None of the above
2%
Show me the answer
#interviewQuestions : 0009
Q: What can we do using Python
Q: Applications of Python
Q: Explain some of the areas where we can use Python
As mentioned before, Python is one of the most widely used language over the web.
It is known for its general purpose nature that makes it applicable in almost each domain of software development. Python as a whole can be used in any sphere of development.
To list few of them here:
○ Databases − Python provides interfaces to all major commercial databases. There by making it useful to create tools or GUI of databases, and also to use with an application which involves interacting with data.
○ Web Applications - We can use Python to develop web applications.
- It provides libraries to handle internet protocols such as HTML and XML, JSON, Email processing, request, beautifulSoup, Feedparser etc.
- There are many well-known web Frameworks such as Django, FastAPI, Pyramid, Flask etc to design and develop web based applications.
○ Desktop GUI Programming −
- Python supports GUI applications that can be installed and run locally on systems like Windows, Linux, iOS etc.
- Python provides Tk GUI library to develop user interface in python based application.
- Some other useful toolkits wxWidgets, Kivy, pyqt that are useable on several platforms. The Kivy is popular for writing multitouch applications.
○ BigData and Data Science -
- Python and Big Data is an inseparable combination when we consider a programming language for big data development phase. Being Open Source, wide community, and a huge library, its best suited for Big Data projects.
- Python has become the number 1 language in Data Science projects.
- Some important packages Pandas, Numpy, SciPy, Theano, Scikit-learn, etc provide everything that a developer needs to work on Big Data and machine learning projects.
- PySpark is also an example of its use.
- Compatible with Hadoop. As Python big data is compatible, similarly Hadoop and big data are synonymous with each other. Hence, Python has been made inherently compatible with Hadoop to work with big data. Python consists of Pydoop package which helps in accessing HDFS API and also writing Hadoop MapReduce programming. Besides that Pydoop enables MapReduce programming to solve complex big data problems with minimal effort.
- An example is IBM using python, they even have a Python SDK for Watson, and they use python extensively.
- Netflix, Spotify use extensively for their recommendation and analytics engine.
○ Console Based Application - We can use Python to develop console based applications. IPython is the best example for this.
○ Multimedia Applications - Python is awesome to perform multiple tasks and can be used to develop audio and video applications.
○ Python is can also be used to develop
- 3D CAD Applications
- Enterprise Applications
- Image Processors and editors
There are several such applications which can be developed using Python
Q: What can we do using Python
Q: Applications of Python
Q: Explain some of the areas where we can use Python
As mentioned before, Python is one of the most widely used language over the web.
It is known for its general purpose nature that makes it applicable in almost each domain of software development. Python as a whole can be used in any sphere of development.
To list few of them here:
○ Databases − Python provides interfaces to all major commercial databases. There by making it useful to create tools or GUI of databases, and also to use with an application which involves interacting with data.
○ Web Applications - We can use Python to develop web applications.
- It provides libraries to handle internet protocols such as HTML and XML, JSON, Email processing, request, beautifulSoup, Feedparser etc.
- There are many well-known web Frameworks such as Django, FastAPI, Pyramid, Flask etc to design and develop web based applications.
○ Desktop GUI Programming −
- Python supports GUI applications that can be installed and run locally on systems like Windows, Linux, iOS etc.
- Python provides Tk GUI library to develop user interface in python based application.
- Some other useful toolkits wxWidgets, Kivy, pyqt that are useable on several platforms. The Kivy is popular for writing multitouch applications.
○ BigData and Data Science -
- Python and Big Data is an inseparable combination when we consider a programming language for big data development phase. Being Open Source, wide community, and a huge library, its best suited for Big Data projects.
- Python has become the number 1 language in Data Science projects.
- Some important packages Pandas, Numpy, SciPy, Theano, Scikit-learn, etc provide everything that a developer needs to work on Big Data and machine learning projects.
- PySpark is also an example of its use.
- Compatible with Hadoop. As Python big data is compatible, similarly Hadoop and big data are synonymous with each other. Hence, Python has been made inherently compatible with Hadoop to work with big data. Python consists of Pydoop package which helps in accessing HDFS API and also writing Hadoop MapReduce programming. Besides that Pydoop enables MapReduce programming to solve complex big data problems with minimal effort.
- An example is IBM using python, they even have a Python SDK for Watson, and they use python extensively.
- Netflix, Spotify use extensively for their recommendation and analytics engine.
○ Console Based Application - We can use Python to develop console based applications. IPython is the best example for this.
○ Multimedia Applications - Python is awesome to perform multiple tasks and can be used to develop audio and video applications.
○ Python is can also be used to develop
- 3D CAD Applications
- Enterprise Applications
- Image Processors and editors
There are several such applications which can be developed using Python
What is the output of the following program :
`print('cd'.partition('cd'))`
`print('cd'.partition('cd'))`
Anonymous Quiz
21%
('cd')
11%
('')
30%
('', 'cd', '')
10%
('cd', '')
28%
Show me the answer.
print("""A
B
C """=="A\nB\nC\n") #What is the output?
B
C """=="A\nB\nC\n") #What is the output?
Anonymous Quiz
24%
True
18%
False
28%
Syntax Error
11%
ABC
10%
Invalid Statement
8%
Show me the answer!
About our channel
* Interview Questions,
* Simple coding problems,
* Quiz etc.
Useful Resources — »»» @python_resources_iGnani
Projects for Practice — »»» @python_projects_repository
You can find* Tasks for Beginners,
* Interview Questions,
* Simple coding problems,
* Quiz etc.
You can use our group
———»»» @python_programmers_club
for discussing regarding the posts or sharing your knowledge.
Our Partner Channels:Useful Resources — »»» @python_resources_iGnani
Projects for Practice — »»» @python_projects_repository
Telegram
Azure, AWS, .net, Python, ML & DataScience
Python Programmers Adda 24/7 to learn python programming from beginners to advanced. If you are looking for starting your journey in Machine Learning / Data Science, then join us.
Resource - @python_resources_iGnani
Practice - @python_projects_repository
Resource - @python_resources_iGnani
Practice - @python_projects_repository
Python Questions pinned «About our channel You can find * Tasks for Beginners, * Interview Questions, * Simple coding problems, * Quiz etc. You can use our group ———»»» @python_programmers_club for discussing regarding the posts or sharing your knowledge. Our Partner Channels:…»
#answer to the question 👆is ————-»»» Dict
Q: Which is faster in performance while searching around a million records plus?
To clarify, both Set and Dict perform search quite fast due to both Set & Dict being implemented using hashtables.
However, Dict performs marginally better compared to Set, but when compared to List or tuple, the difference is huge.
Q: Which is faster in performance while searching around a million records plus?
To clarify, both Set and Dict perform search quite fast due to both Set & Dict being implemented using hashtables.
However, Dict performs marginally better compared to Set, but when compared to List or tuple, the difference is huge.
Telegram
Python Questions
Which is faster in performance while searching around a million records plus?
List / Set / Dict / Tuple / All have the same performance / See the answer
List / Set / Dict / Tuple / All have the same performance / See the answer
x = 1.3 + 2.3
print(x == 3.6)
# what is the output? Can you explain?
print(x == 3.6)
# what is the output? Can you explain?
Anonymous Quiz
15%
3.6
63%
True
14%
False
2%
1.3
1%
2.3
6%
Show me the answer
Which of the following functions will return an iterable object in Python 3+ ?
Anonymous Quiz
11%
len()
10%
ord()
16%
xrange()
44%
range()
8%
None of the above
11%
Show me the answer
x, y, z = 5, 10, 15
z = x <= y
#What is the value of z? Explain why
z = x <= y
#What is the value of z? Explain why
Anonymous Quiz
11%
5
18%
15
34%
True
26%
False
5%
None of the above
7%
Show me the answer
#interviewQuestions : 0010
Q: What is a Namespace in Python?
Q: What is a Namespace in Python?
A namespace is basically a system to make sure that all the names of each and every object in a Python program are unique and can be used without any conflict.
You might already know that everything in Python like strings, lists, functions, etc. is an object. Python implements namespaces as dictionaries. There is a name-to-object mapping, with the names as keys and the objects as values. Multiple namespaces can use the same name and map it to a different object. Here are a few examples of namespaces:
Local Namespace: This namespace includes local names inside a function. This namespace is created when a function is called, and it only lasts until the function returns.
Global Namespace: This namespace includes names from various imported modules that you are using in a project. It is created when the module is included in the project, and it lasts until the script ends.
Built-in Namespace: This namespace includes built-in functions and built-in exception names.