Fullstack - Cafe - Tech Interview Plan: Q1: What Are The Built-In Types Available in Python?

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5
At a glance
Powered by AI
The document discusses various Python concepts like built-in types, characteristics, modifying strings etc.

Immutable built-in datatypes of Python Numbers Strings Tuples Mutable built-in datatypes of Python List Dictionaries Sets

Here are a few key points: Python is an interpreted language. That means that, unlike languages like C and its variants, Python does not need to be compiled before it is run. Other interpreted languages include PHP and Ruby. Python is dynamically typed, this means that you don't need to state the types of variables when you declare them or anything like that. You can do things like x=111 and then x="I'm a string" without error Python is well suited to object orientated programming in that it allows the definition of classes along with composition and inheritance. Python does not have access specifiers (like C++'s public , private ), the justification for this point is given as "we are all adults here" In Python, functions are first-class objects. This means that they can be assigned to variables, returned from other functions and passed into functions. Classes are also first class objects Writing Python code is quick but running it is often slower than compiled languages. Fortunately, Python allows the inclusion of C based extensions so bottlenecks can be optimised away and often are. The numpy package is a good example of this, it's really quite quick because a lot of the number crunching it does isn't actually done by Python

FullStack.

Cafe - Kill Your Tech Interview

FullStack.Cafe - Tech Interview Plan

Q1: What are the built-in types available In Python? ☆

Topics: Python

Answer:

Immutable built-in datatypes of Python

Numbers
Strings
Tuples

Mutable built-in datatypes of Python

List
Dictionaries
Sets

Q2: Name some characteristics of Python? ☆

Topics: Python

Answer:

Here are a few key points:

Python is an interpreted language. That means that, unlike languages like C and its variants, Python does
not need to be compiled before it is run. Other interpreted languages include PHP and Ruby.
Python is dynamically typed, this means that you don't need to state the types of variables when you
declare them or anything like that. You can do things like x=111 and then x="I'm a string" without error
Python is well suited to object orientated programming in that it allows the definition of classes along
with composition and inheritance. Python does not have access specifiers (like C++'s public , private ), the
justification for this point is given as "we are all adults here"
In Python, functions are first-class objects. This means that they can be assigned to variables, returned
from other functions and passed into functions. Classes are also first class objects
Writing Python code is quick but running it is often slower than compiled languages. Fortunately, Python
allows the inclusion of C based extensions so bottlenecks can be optimised away and often are. The numpy
package is a good example of this, it's really quite quick because a lot of the number crunching it does isn't
actually done by Python

Q3: How do I modify a string? ☆

Topics: Python

Answer:

You can’t, because strings are immutable. In most situations, you should simply construct a new string from the
various parts you want to assemble it from.

Page 1 of 5
FullStack.Cafe - Kill Your Tech Interview

Q4: Name some benefits of Python ☆☆

Topics: Python

Answer:

Python is a dynamic-typed language. It means that you don’t need to mention the data type of variables
during their declaration.
Python supports object orientated programming as you can define classes along with the composition and
inheritance.
Functions in Python are like first-class objects. It suggests you can assign them to variables, return from
other methods and pass as arguments.
Developing using Python is quick but running it is often slower than compiled languages.
Python has several usages like web-based applications, test automation, data modeling, big data analytics
and much more.

Q5: What is PEP 8? ☆☆

Topics: Python

Answer:

PEP 8 is the latest Python coding standard, a set of coding recommendations. It guides to deliver more
readable Python code.

Q6: Why would you use the "pass" statement? ☆☆

Topics: Python

Answer:

Python has the syntactical requirement that code blocks cannot be empty. Empty code blocks are however useful
in a variety of different contexts, for example if you are designing a new class with some methods that you don't
want to implement:

class MyClass(object):
def meth_a(self):
pass

def meth_b(self):
print "I'm meth_b"

If you were to leave out the pass, the code wouldn't run and you'll get an error:

IndentationError: expected an indented block

Other examples when we could use pass :

Ignoring (all or) a certain type of Exception


Deriving an exception class that does not add new behaviour
Testing that code runs properly for a few test values, without caring about the results

Page 2 of 5
FullStack.Cafe - Kill Your Tech Interview

Q7: What is lambda functions in Python? ☆☆

Topics: Python

Answer:

A lambda function is a small anonymous function. A lambda function can take any number of arguments, but
can only have one expression.

Consider:

x = lambda a : a + 10
print(x(5)) # Output: 15

Q8: When to use a tuple vs list vs dictionary in Python? ☆☆

Topics: Python

Answer:

Use a tuple to store a sequence of items that will not change.


Use a list to store a sequence of items that may change.
Use a dictionary when you want to associate pairs of two items.

Q9: What is pickling and unpickling? ☆☆

Topics: Python

Answer:

The pickle module implements a fundamental, but powerful algorithm for serializing and de-serializing a Python
object structure.

Pickling - is the process whereby a Python object hierarchy is converted into a byte stream,
Unpickling - is the inverse operation, whereby a byte stream is converted back into an object hierarchy.

Q10: What is negative index in Python? ☆☆

Topics: Python

Answer:

Python sequences can be index in positive and negative numbers. For positive index, 0 is the first index, 1 is the
second index and so forth. For negative index, (-1) is the last index and (-2) is the second last index and so forth.

Q11: What are local variables and global variables in Python? ☆☆

Topics: Python

Answer:

Page 3 of 5
FullStack.Cafe - Kill Your Tech Interview

Global Variables: Variables declared outside a function or in global space are called global variables. These
variables can be accessed by any function in the program.

Local Variables: Any variable declared inside a function is known as a local variable. This variable is present
in the local space and not in the global space.

Q12: What are the rules for local and global variables in Python?
☆☆

Topics: Python

Answer:

In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a
value anywhere within the function’s body, it’s assumed to be a local unless explicitly declared as global.

Requiring global for assigned variables provides a bar against unintended side-effects.

Q13: What are some drawbacks of the Python language? ☆☆

Topics: Python

Answer:

The two most common valid answers to this question (by no means intended as an exhaustive list) are:

The Global Interpreter Lock (GIL). CPython (the most common Python implementation) is not fully thread
safe. In order to support multi-threaded Python programs, CPython provides a global lock that must be held
by the current thread before it can safely access Python objects. As a result, no matter how many threads or
processors are present, only one thread is ever being executed at any given time. In comparison, it is worth
noting that the PyPy implementation discussed earlier in this article provides a stackless mode that supports
micro-threads for massive concurrency.
Execution speed. Python can be slower than compiled languages since it is interpreted. (Well, sort of. See our
earlier discussion on this topic.)

Q14: Does Python have a switch-case statement? ☆☆

Topics: Python

Answer:

In Python, we do not have a switch-case statement. Here, you may write a switch function to use. Else, you may
use a set of if-elif-else statements. To implement a function for this, we may use a dictionary.

def switch_demo(argument):
switcher = {
1: "January",
2: "February",
3: "March",
4: "April",
5: "May",
6: "June",
7: "July",
8: "August",
9: "September",
10: "October",

Page 4 of 5
FullStack.Cafe - Kill Your Tech Interview

11: "November",
12: "December"
}
print switcher.get(argument, "Invalid month")

Q15: What Is The Benefit Of Using Flask? ☆☆

Topics: Python

Answer:

Flask is part of the micro-framework. Which means it will have little to no dependencies on external libraries. It
makes the framework light while there is little dependency to update and less security bugs.

Q16: Suppose lst is [2, 33, 222, 14, 25], What is lst[-1]? ☆☆

Topics: Python

Problem:

Suppose lst is [2, 33, 222, 14, 25] , What is lst[-1] ?

Solution:

It's 25 . Negative numbers mean that you count from the right instead of the left. So, lst[-1] refers to the last
element, lst[-2] is the second-last, and so on.

Q17: How do you list the functions in a module? ☆☆

Topics: Python

Answer:

Use the dir() method to list the functions in a module:

import some_module
print dir(some_module)

Q18: What are descriptors? ☆☆

Topics: Python

Answer:

Descriptors were introduced to Python way back in version 2.2. They provide the developer with the ability to
add managed attributes to objects. The methods needed to create a descriptor are __get__ , __set__ and
__delete__ . If you define any of these methods, then you have created a descriptor.

Descriptors power a lot of the magic of Python’s internals. They are what make properties, methods and even the
super function work. They are also used to implement the new style classes that were also introduced in Python
2.2.

Page 5 of 5

You might also like