0% found this document useful (0 votes)
3 views5 pages

Interview

The document provides an overview of Python programming concepts including namespaces, classes, and data types. It covers built-in functions, object-oriented programming principles like encapsulation and polymorphism, and basic data structures such as lists and arrays. Additionally, it discusses file handling, type conversion, and sorting algorithms, along with examples and code snippets.

Uploaded by

Junaid Mohsin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views5 pages

Interview

The document provides an overview of Python programming concepts including namespaces, classes, and data types. It covers built-in functions, object-oriented programming principles like encapsulation and polymorphism, and basic data structures such as lists and arrays. Additionally, it discusses file handling, type conversion, and sorting algorithms, along with examples and code snippets.

Uploaded by

Junaid Mohsin
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

1.

Python (basics) + intermediate


2. MySQL

Namespace:
Name - which talks about a unique identifier
Space - talks about something related to scope
There are some functions like print(), id() and so on which are built-in name-spaces, as they are pre-
defined. A global namespace gets created when a user creates a module. After this, the creation of local
functions creates the local namespace. Local namespace is created when we create a local function.

The built-in namespace encompasses the global namespace and the global namespace encompasses the
local namespace.

A local namespace is is created temporarily when the function is called and is cleared once the function
finishes executing. Built-in namespace comprises the built-in functions provided by Python.

Class - it is basically an assemblage of objects that share in some property, attribute, or characteristic.
For example, employee is a class, and in that class we can have an object Harry, another object, Rohan,
another object, Charles, and so on; sharing in the common properties of being an employee or being in
the employee class in colliqual terms.

Example:
class Employee:
no_of_leaves = 8
employee1 = Employee()
employee2 = Employee()
employee3 = Employee()
#we created 3 instances of that class
[Link] = 'Harry'
[Link] = 485
[Link] = 'Instructor'
[Link] = 'Rohan'
[Link] = 4554
[Link] = 'Student'

Init function: it plays the role of a constructor in Python. The init function is called every time an object is
created. We use it to let the class initialize the object's attributes, and it is only used within classes.
class Person:

# init method or constructor


def __init__(self, name):
[Link] = name
# Sample Method
def say_hi(self):
print('Hello, my name is', [Link])
p = Person('Nikhil')
p.say_hi()

Then there are immutable data types. And there are mutable data types. Like set, lists, dictionary.

A local variable is a variable that is specifically instantiated within a function. Whereas a global variable is
declared outside the function. If you attempt to access the local variable outside the defined function,
you will encounter an error.

Python allows for conversion of data types. This is called type conversion. Implicit type conversion ->
Python automatically converts
Explicit type conversion -> Involves user explicitly changing to desired data type

Python array:
cars_array = ['Ford', 'Bmw']
x = cars_array[0]
print(x)

cars_array[0] = 'Toyota'
To modify the value
x = len(cars_array)

Arrays are data structures that hold fixed sized elements of the same time. Whereas lists are versatile
data types that allows for homogenity, that can hold elements of different types and sizes. They consume
less memory compared to lists.

Reversed list:
list1 = [1,2,3,4]
[Link]()
print(list1)

what does [-1] do: it does the same


list1 = [1,2,3,4]
reversed_list = list[::-1]
print(reversed_list)

reversing all characters:


name = input('input name')
print(name[::-1])

List = ['He', 'loves', 'to']


shuffle().list
print(list)

Reverse indexing
012345
abcdef
-6-5-4-3-2-1
when we access elements from opposite sides

Map function: it has two parameters, a function and a iterable. Allows you to apply a specified function
to every element within an iterable. This can be then passed onto a list.
def calculatesq(n):
return n*n
numbers =(2,3,4,5)
result = map(calculatesq, numbers)
print(list(result))

Python comprehensions:
list = [1,2,3,4]
squared_list = [x**2 for x in list]
print(squared_list)

Q: write a program to replace a word in a sentence.


use replace('a', 'b')
Q: print an item of the list from index 2

Python has all the OOPs concepts such as inheritance, polymorphism, and more with the exeption of
access specifiers. It also doesnt support encapsulation. Though, it has a convention it can use for data
hiding (You could prefix a data member with 2 underscores.)

reading a file
file = open("[Link]", "r")
print([Link]())
[Link]()

How will you remove duplicate elements: (we will use set function)
demo_list = [5,3,5,5,6,7,7,8]
unique_list = set(demo_list)
print(unique_list)
Q: how can files be deleted in python?
import os
[Link]("[Link]")

Q: count the number of files


count = 0
filename = "[Link]"
file = open("[Link]", "r")
for i in [Link]():
if [Link]():
count +=1

Projects:
It is basically an e-commerece website which specializes in website developement.
Django is a web framework.

What is Polymorphism is python?


It is the ability of a code to take multiple forms. If a parent class has a method named XYZ, then the child
class can also have a method named XYZ having its own parameters and properties.

Encapsulation in python refers to the process of wrapping up the variables and different functions into a
single entity or capsule. Eg: python class

The limitations of list is that they dont support vectorized operations. Numpy you can use to perform
vector and matrix operations.

Self: an object or instance of a class


Slicing: used to extrapolate a specific range of elements from a sequential data type (list, tupple, strings)

Multithreading: Python has an instructor called GIL. It ensures that only one of your threats execute at
one time. The thread aquires the GIL, does work, then passes it onto the next thread. It occurs
spordically giving the illusion of parralel execution to the human observer. Though, they are executing
sequentially.

Two arrays:
[Link] = ( )
[Link] = ( )

to get percentile:
import numpy as np
a = [Link]([1,2,3,4,5)]
p = [Link](a,50)
print(p)

to return the sum of a list of numbers:


create a function called sum
if list only has 1 element, it is going to return that element
otherwise return num[0] + sum(num[1:])

sorting algorithm:
my_list = ["8", "4", "3", "6", "2"]
for i in my_list:
my_list.sort()
print(my_list)

bubble sort:
fibonacci sequence:
star triangle:

You might also like