Spotify Technology Python Interview Questions Answers

Enlist some of 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.

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)

What is the output of print str[2:] if str = ‘Hello World!’?

It will print characters starting from 3rd character. Output would be llo World!.

What is the output of print str * 2 if str = ‘Hello World!’?

It will print string two times. Output would be Hello World!Hello World!.

What is the output of print str + “TEST” if str = ‘Hello World!’?

It will print concatenated string. Output would be Hello World!TEST.

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

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

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 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.
Spotify Technology Most Frequently Asked Latest Python Interview Questions Answers
Spotify Technology Most Frequently Asked Latest Python Interview Questions Answers

What is a Frame in Python GUI?

A 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, Radio Button, etc.

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 similar fashion as while and for loop. It takes in 2 compulsory parameters and 1 optional parameter.

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.

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 as 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.

Does Python Supports Switch Case statements?

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

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()

button 1 is a variable to hold the Button Element and frame 1 is the name of the Frame variable onto to which we want to adjust our Button. It is mandatory to define the Frame first.

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

How will you get the min alphabetical character from the string?

min(str) − Returns the min alphabetical character from the string str.

How will you replaces all occurrences of old substring in string with new string?

replace(old, new [, max]) − Replaces all occurrences of old in string with new or at most max occurrences if max given.

How will you remove all leading and trailing whitespace in string?

strip([chars]) − Performs both lstrip() and rstrip() on string.

How will you change case for all letters in string?

swapcase() − Inverts case for all letters in string.

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.


How will you get the max alphabetical character from the string?

max(str) − Returns the max alphabetical character from the string str.

How will you get titlecased version of string?

title() − Returns “titlecased” version of string, that is, all words begin with uppercase and the rest are lowercase.

How will you convert a string to all uppercase?

upper() − Converts all lowercase letters in string to uppercase.

How will you check in a string that all characters are decimal?

isdecimal() − Returns true if a unicode string contains only decimal characters and false otherwise.

What is Django Framework in Python?

Django is a high-level Python framework which 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.

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.

Enlist the Non-Mutable Built-in types in Python programming environment?

The Non-Mutable Built-in types in Python Programming Environment are as follows:

1. Tuples
2. Numbers
3. Strings

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 interpreter decide the scope itself. Proper indentations, if not used will normally generate an error.

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.

What Are The Rules For Local And Global Variables In Python?

In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a new value anywhere within the function's body, it's assumed to be a local. If a variable is ever assigned a new value inside the function, the variable is implicitly local, and you need to explicitly declare it as 'global'.
Though a bit surprising at first, a moment's consideration explains this. On one hand, requiring global for assigned variables provides a bar against unintended side-effects. On the other hand, if global was required for all global references, you'd be using global all the time. You'd have to declare as global every reference to a builtin function or to a component of an imported module. This clutter would defeat the usefulness of the global declaration for identifying side-effects.

How Do I Share Global Variables Across Modules?

The canonical way to share information across modules within a single program is to create a special module (often called config or cfg). Just import the config module in all modules of your application; the module then becomes available as a global name. Because there is only one instance of each module, any changes made to the module object get reflected everywhere.

For example:

config.py:

x = 0 # Default value of the 'x' configuration setting
mod.py:
import config
config.x = 1
main.py:
import config
import mod
print config.x

How Do I Copy An Object In Python?

In general, try copy.copy() or copy.deepcopy() for the general case. Not all objects can be copied, but most can.
Some objects can be copied more easily. Dictionaries have a copy() method:
newdict = olddict.copy()
Sequences can be copied by slicing:
new_l = l[:]


What is the purpose pass statement in python?

pass statement − The pass statement in Python is used when a statement is required syntactically but you do not want any command or code to execute.

How will you randomizes the items of a list in place?

shuffle(lst) − Randomizes the items of a list in place. Returns None.

How will you capitalizes first letter of string?

capitalize() − Capitalizes first letter of string.

How will you check in a string that all characters are alphanumeric?

isalnum() − Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise.

How will you check in a string that all characters are digits?

isdigit() − Returns true if string contains only digits and false otherwise.

How will you check in a string that all characters are in lowercase?

islower() − Returns true if string has at least 1 cased character and all cased characters are in lowercase and false otherwise.

Post a Comment

Previous Post Next Post