Saturday, May 30, 2020

Python Interview Questions



Top 50+ Python Interview Questions

Below 50+ are the most frequently asked Python interview questions with answers that will help you to cracked interviews.

1. What Programming Paradigm does Python supports?

Python supports both the Procedural Programming approach as well as the Object-Oriented Programming Approach. Moreover, you can use both approaches in a single Python program.

2. Enlist the built-in datatypes that Python provides.

The datatypes provide by Python are as follows:
1. List
2. Tuple
3. Dictionary
4. String
5. Number
6. Set

3. Enlist a difference between Tuples and Lists.

Tuples and Lists are used to store a sequence of data within them. A difference between them is that Tuples once defined cannot be altered under any circumstances whereas Lists can be altered.

4. Enlist Popular Frameworks of Python.

Major Frameworks: Django and Pyramid
Minor Frameworks: Bottle and Flask

5. What is Lambda in Python specification?

It is a single expression which is an Anonymous Method often used as an Inline function.

6. Enlist the Applications of Python Programming.

1. Web Application Development and Web Frameworks such as Django and Pyramid.
2. Game Development
3. Desktop Based Applications
4. Micro Frameworks such as Bottle and Flask

7. What is the grid() method used for in Python?

grid() method is the one that all the widgets in a Python GUI Program’s frame have. It’s associated with a layout manager, which lets you arrange widgets in a Frame. 

8. Is Python a Scripting Language?

Python is a General-Purpose Programming Language or rather a Multi-Purpose Programming Language. It is also a Scripting Language as it can be used to combine it into HTML Code used for Web Development.

9. Explain modes in Python Programming Environment.

Script Mode: This mode is used to compile and save Python programs which is not possible in the Interactive mode.
Interactive Mode: This mode can be thought of as a scratchpad to check out codes in Python Environment.
In order to make it executable, we should prefer Script Mode. 

10. What is Slicing in Python?

Slicing is a terminology that is used to generate sliced or modified output from Lists and Tuples.

11. Enlist commonly used Classes in games Module in livewires Package?

The commonly used Classes in Games Module under Livewires Package are as follows:
  • Text
  • Screen
  • Sprite
  • Message

12. What is the difference between Print(“Hello World”) and print(“Hello World”)?

Python Programming Language is Case-Sensitive. So, Print(“Hello World”) would give an error as the syntax is not correct. However, print(“Hello World”) would work perfectly.

13. How do you create a RadioButton Element in Python?

The RadioButton Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:
radiobutton1 = Radiobutton(frame1, text= “C Programming”, value=0)
radiobutton1.grid()
radiobutton1 is a variable to hold the Radio Button Element and frame1 is the name of the Frame variable onto to which we want to adjust our Radio Button. The default value of a Radio Button is 1 which means ‘Selected’. We need to set it to value=0.

14. How to take input from the User in Python?

Python provides a built-in method to accept input from the user.
It is as follows: input(“Enter the Input”)
However, in order to store the input in a variable, you must write a variable name before the input() method.
It can be done as follows: var1=input(“Enter the input”)

15. How to terminate a line of code in Python?

Python is an extremely efficient and easy to use language. You can terminate a Python line of code using a Semi-Colon. However, it is not mandatory to use a Semi-colon at the end of every line. It is up to you if you want to use it or not.

16. Enlist various Exceptions identified by Python?

The various exceptions identified by Python Environment are as follows:
1. IOError
2. IndexError
3. KeyError
4. NameError
5. SyntaxError
6. ValueError
7. TypeError

17. What is namespace in Python?

For every variable that is introduced in Python, there is a namespace that is associated with the place holder for that particular variable. It is a place holder where a variable can be linked to the object placed.

18. What is a Frame in Python GUI?

Frame in Python can be related as a storage holder for other Graphical User Interface or GUI elements such as Label, Text Entry, Text Box, Check Button, RadioButton, etc. 

19. How do you include comment feature in a Python program?

Python Programming Environment supports good features for comment as it helps the developers to document the code without any confusion. You can write a comment in a Python program using the following command:
Syntax:
# Comment Here

20. What is the difference between the input() method and the raw_input() method?

raw_input() method returns string values whereas input() method returns integer values.
Input() method was used in Python 2.x versions whereas Python 3.x and later versions use raw_input() method. However, the input()method has been replaced by the raw_input() method in Python 3.x.

21. What is the difference between Lists and Tuples in terms of Syntax?

Both Lists and Tuples are used to store a sequence of data within them. However, a major difference between them is that Tuples use parentheses( ) in its syntax whereas Lists use Brackets in its syntax [ ].

22. What is the difference between the Text Entry element and Text Box element in Tkinter Module?

A Text Entry element is used to receive an input of only one single line whereas a Text Box provides a space to receive input for multiple lines.

23. How do you create a Check Button Element in Python?

The CheckButton class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:
checkbutton1 = Checkbutton(frame1, text= “C Programming”)
checkbutton1.grid()
checkbutton1 is a variable to hold the Check Button Element and frame1 is the name of the Frame variable onto which we want to adjust our Check Button. It takes in a parameter named Text which is used to display the name for the Check Button.

24. What is the difference between a Lambda and Def?

A Def is a function that can contain multiple expressions whereas a Lambda can contain only one single expression. A Def method can contain return statements whereas a Lambda cannot contain return statements. A Lambda can be used inside lists and dictionaries. 

25. What is a Line Continuation Character in Python?

Line continuation character in Python is the one which lets us to continue a single line of code on the next line without changing its meaning. We can do it using a Line continuation character provided by Python which is a Backslash. 

26. How do you define the dimensions of a window in a Python Graphics Program?

We can define the dimensions i.e., width and height of a Window in a Python GUI programming. It can be defined using the geometry() method. It takes in two parameters: width and height respectively.
Example: geometry(“width * height”)

27. Enlist the Looping constructs available in Python.

Python provides using two looping constructs and these are For Loop and While Loop. Both of these looping constructs are the same. The only difference is of the syntax that both of these use.

28. What is the range() method in Python?

Range() method is Python is used as a Looping construct. It takes in 2 mandatory parameters and 1 optional parameter.
Example: range(1,10,2)
This method prints numbers after every alternate iterations between 1 and 10. It prints 1 3 5 7 9.

29. Are indentations mandatory to use in Python?

Indentations are very much important to use in Python. We normally do not use braces to indicate the scope of a function in a Python program. Indentation lets the Python Interpreter to understand the scope of a function automatically. Not using indentations properly in a Python program generates errors normally. 

30. Which method is used to find out the location of the pointer in a file?

The tell() method is used to return the current location or position of the read/write pointer within the file. This method doesn’t require any parameter to be passed in it.
Syntax:
FileVariableName.tell() 

31. Enlist the Mutable Built-in types in the Python programming environment.

The Mutable Built-in types in Python Programming Environment are as follows:
1. Sets
2. Dictionaries
3. Lists

32. How do you create a Text Box Element in Python?

The Text Box Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:
text1 = Text(frame1, width = 35, height = 5)
text1.grid()
text1 is a variable to hold the Text Element and frame1 is the name of the Frame variable onto to which we want to adjust our Text Box. It has two parameters viz., width, and height that define its dimensions.
It is mandatory to define the Frame first.

33. Enlist some of the GUI Elements in Python Tkinter module?

Frame, Label, Text Entry, Check Button, Radio Button, Text Box are some of the few Tkinter GUI Elements used in Python.

34. Which method is used to set the file pointer at a particular location?

The seek() method is used to set the File pointer to a particular position in the Text File. It takes in two parameters out of which the first one is mandatory and the second one is optional.
Syntax:
seek(location, source) 

35. Why is Finally Block used in Python Exception Handling?

A Finally block is generally used in association with try and catch blocks in Python. A Finally block executes itself no matter if an error occurs at run time or not. It is the default execution block in the Python Exception Handling technique.

36. What is a DocString and what is it used for?

A DocString represents Document String that is used to Document Python Modules, Classes and Methods. 

37. How is the memory management process in Python?

Like other programming environments, Python Programming Environment has Garbage Collection Techniques that manages the Memory efficiently. Moreover, the memory is managed by the Private Heap which is ultimately managed by the Python Memory Manager.

38. What is another method for Using Loops with While Loop and For Loop?

Python provides a method named as range() that provides looping constructs. It works in a similar fashion as a while and for loop. It takes in 2 compulsory parameters and 1 optional parameter.

39. How can we import different packages in a Python program?

Syntax:
from Package_Name import Module_Name
Example:
from livewires import games

40. Does Python Compiled Code contains Byte-Codes?

No. Python is primarily an Interpreted Language. However, at first, the .py file is compiled to something called Python Byte-Code which is not a file that contains Binary digits like other Programming environments. It actually contains Python-specific instructions that helps in optimizing the startup speed.

41. Does Python Support Switch Case statements?

No, Python does not have provision for Switch Case statements. However, it provides an alternative called ‘One-to-One Mapping’.

42. How do you create a Button Element in Python?

The Button Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:
button1 = Button(frame1, text = “I am a Button”)
button1.grid()
button1 is a variable to hold the Button Element and frame1 is the name of the Frame variable onto to which we want to adjust our Button. It is mandatory to define the Frame first.

43. How do you print the sum of digits from 1 to 50 in Python?

print(sum(range(1,51))
This command would print in the sum of digits from 1 to 50.

44. What is PEP 8 in Python?

PEP 8 is a set of recommendations about writing Python Code so as to make it readable and useful for other programmers. It is more of a coding convention.

45. What is a Decorator in Python?

Decorators allow you to wrap a method or a class function that executes a set of code lines before or after the execution of the original code. Decorator also allows to inject or modify code in methods or classes.

46. What is Django Framework in Python?

Django is a high-level Python framework that is used primarily for Web Development. This framework encourages fast and efficient development with pragmatic and clean design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.

47. Is Python a Compiled or an Interpreted Programming Language?

Python programs have the extension .py. These source files are first compiled to Byte Codes (which does not contain the binary codes). These Byte Code files helps in startup speed optimization. These byte-codes are then sent to the Python Virtual Machine where lines of codes are read one after another which means that it is interpreted. 

48. Enlist the Non-Mutable Built-in types in the Python programming environment.

The Non-Mutable Built-in types in Python Programming Environment are as follows:
1. Tuples
2. Numbers
3. Strings

49. How can we define Scope in a Python program?

Python programming environment does not support the use of Braces for Defining Scope for a variable or a method. However, it uses Indentations to let the Python compiler decide the scope itself. Proper indentations, if not used will normally generate an error.

50. What is Tkinter in Python and what is it used for?

Tkinter is a Python module available for Python programmers for the development of Graphical User Interface (GUI) programs. Tkinter module is used to import the methods required for the creation of GUI in a Python program.

51. How are exceptions handled in Python?

An Exception is raised by Python when an error occurs at program run-time. Python Exceptions can be caught using try and catch blocks. When you are suspicious of a statement, move it into the try block and on error, the control moves into the catch block, and a pre-defined activity can be executed which helps to avoid an abnormal termination of the program.

52. How do you create a Label Element in Python?

The Label Class is available in Tkinter Module. We first need to import it and then we can take in a frame label by the following command:
label1 = Label(frame1, text = “Here is a label!”)
label1.grid()
label1 is a variable to hold the Label Element and frame1 is the name of the Frame variable onto to which we want to adjust our Label.
So this was the list of some important Python interview questions and answers that are very frequently asked in the interviews. If you found any information incorrect or missing in the above list then please mention it by commenting below.

Friday, May 29, 2020

What is OData? (Part-3)


In my previous two blogs, I have covered the basics of how the Internet works, HTTP and what are REST-based services. So, now that we have laid the foundation we will start with understanding what is OData protocol.
Previous Blogs in the series:
What is OData?
“Open Data Protocol (OData) is an open data access protocol from Microsoft that allows the creation and consumption of query-able and interoperable RESTful APIs in a simple and standard way”.
The protocol enables the Clients to publish and manipulate the resource identified by URIs and defined in a data model using simple HTTP messages.
To put it in simple words, OData is an open source to exchange data over the Internet. The server hosts the data and clients can call this service to retrieve the resources and manipulate them. Servers expose one or more endpoints which are services that refer to the resources. Clients need to know these server-side endpoints to call the service to query or manipulate the data. The protocol is HTTP based and designed with a RESTful mindset which means it follows the constraints to be called as a RESTful service.
Since the protocol is HTTP based, any programming language with HTTP stack can be used to consume OData services. Existing Client-side libraries can be used to transform the JSON or ATOM payloads from the server into objects making programming simple. On the other hand, many libraries exists on the server-side to generate the payloads in ATOM or JSON from the existing data.
It is important to note that both Client-side and Server-side development can be in completely different programming languages till the time both are able to communicate via HTTP.
Clients consume the service to query and manipulate the data from OData Services and are also called as Consumers of OData Service.
Similarly, Servers that expose the OData services via endpoints are known as Producers of Odata services.
ODataProtocol.jpg
So, we now know that in OData protocol, the resources are exposed in two formats; XML based Atom and JSON.
A brief description of what is Atom ad JSON.
Atom is a combination of two protocols, Atom Syndication and Atom Publishing protocol. The Atom Syndication Format is an XML language used for web feeds, while the Atom Publishing Protocol (AtomPub or APP) is a simple HTTP-based protocol for creating and updating web resources.
JSON stands for JavaScript Object Notation is a lightweight data-interchange format. JSON is self-descriptive and easy to use and is completely language-independent.
Advantages with OData
There is a lot of data on the web today but lot of it is locked up in different specific applications or formats and different to access from outside. Many Organizations have now started exposing data using REST based services however, it is difficult to write applications which works with multiple data sources as each provider will expose the data in a slightly different way. OData service producer can expose its service along with metadata which contains the semantics for consumption. OData exploits common formats like XML, Atom, and JSON for communication which are commonly understood. Clients can now understand these OData services using generic tools and can combine information from multiple data sources.
Exposing your data with OData services comes with multifold advantages. For example, as we mentioned earlier, as a consumer, you need not worry about the programming language used by producer as long as the services are exposed as OData service.
ODataAdvantages.jpg

ODBC for the Web

ODBC (Open Database Connectivity) is a standard API to access the database management systems independent of the database management systems or operating systems. ODBC manages this by adding drivers between the Application layer and the DBMS to translate the queries fired by application into instructions which DBMS can understand.
OData has similarities with the ODBC in the sense that here, OData provides the middleware between producers and consumers to communicate data. There is a uniform way to consume data and is independent of the producer much like ODBC. The fact that OData is based on HTTP RESTful services makes it the ODBC for the Web!
In my next blog, I will talk about SAP Netweaver Gateway, SAP OData Channel and the main elements of an OData service.

Saturday, May 23, 2020

What is Software as a Service (SaaS)?


Software as a Service (SaaS)


Software as a Service (SaaS) is a software distribution model in which a third-party provider hosts applications and makes them available to customers over the Internet. SaaS is one of three main categories of cloud computing, alongside Infrastructure as a Service (IaaS) and Platform as a Service (PaaS).
SaaS is closely related to the Application Service Provider (ASP) and on-demand computing software delivery models. The hosted application management model of SaaS is similar to ASP, where the provider hosts the customer’s software and delivers it to approved end-users over the internet.  
In the software on-demand SaaS model, the provider gives customers network-based access to a single copy of an application that the provider created specifically for SaaS distribution. The application’s source code is the same for all customers and when new features or functionalities are rolled out, they are rolled out to all customers. Depending upon the Service Level Agreement (SLA), the customer’s data for each model may be stored locally, in the cloud, or both locally and in the cloud.
Organizations can integrate SaaS applications with other software using Application Programming Interfaces (APIs). For example, a business can write its own software tools and use the SaaS provider's APIs to integrate those tools with the SaaS offering.
here are SaaS applications for fundamental business technologies, such as email, sales management, Customer Relationship Management (CRM), financial management, Human Resource Management (HRM), billing, and collaboration. Leading SaaS providers include Salesforce, Oracle, SAP, Intuit, and Microsoft.
SaaS applications are used by a range of IT professionals and business users, as well as C-level executives.




Advantages of SaaS

SaaS removes the need for organizations to install and run applications on their own computers or in their own data centers. This eliminates the expense of hardware acquisition, provisioning, and maintenance, as well as software licensing, installation, and support. Other benefits of the SaaS model include:
Flexible payments: Rather than purchasing software to install, or additional hardware to support it, customers subscribe to a SaaS offering. Generally, they pay for this service on a monthly basis using a pay-as-you-go model. Transitioning costs to a recurring operating expense allows many businesses to exercise better and more predictable budgeting. Users can also terminate SaaS offerings at any time to stop those recurring costs.
Scalable usage: Cloud services like SaaS offer high vertical scalability, which gives customers the option to access more, or fewer, services or features on-demand.
Automatic updates: Rather than purchasing new software, customers can rely on a SaaS provider to automatically perform updates and patch management. This further reduces the burden on in-house IT staff.
Accessibility and persistence: Since SaaS applications are delivered over the Internet, users can access them from any Internet-enabled device and location.

Disadvantages of SaaS

SaaS also poses some potential disadvantages. Businesses must rely on outside vendors to provide the software, keep that software up and running, track and report accurate billing, and facilitate a secure environment for the business' data. Issues can arise when providers experience service disruptions, impose unwanted changes to service offerings, or experience a security breach, all of which can have a profound effect on the customers' ability to use SaaS offerings. To proactively mitigate these issues, customers should understand their SaaS provider's service-level agreement, and make sure it is enforced.

10 Popular Software as a Service (SaaS) Examples

1.    Salesforce.com
2.    Microsoft Office 365
3.    Box
4.    Google Apps
5.    Amazon Web Services
6.    Concur
7.    Zendesk
8.    DocuSign
9.    Dropbox
10. Slack