Python Learning and Interview - Imtiaz211/interviews GitHub Wiki
Learning for Interview Process
-
Python Function
- A function is a block of code which only runs when it is called.
- A
lambda
function is a small anonymous function. Alambda
function can take any number of arguments, but can only have one expression. - The power of lambda is better shown when you use them as an anonymous function inside another function.
- lambda arguments : expression
- x = lambda a, b : a * b
- print(x(5, 6))
- You can pass data, known as parameters, into a function.
- A function can return data as a result with
return
statement function
definitions cannot be empty, but if you for some reason have a function definition with no content, put in thepass
statement to avoid getting an error.- Function is defined using the
def
keyworddef
my_function(fname):- print(fname + "Refresh")
- Arbitrary Arguments, *args
- def my_function(*kids):
- print("The youngest child is " + kids[2])
- my_function("Emil", "Tobias", "Linus")
- def my_function(*kids):
-
List
- mylist = ["apple", "banana", "cherry"]
- Lists are used to store multiple items in a single variable.
- List items are ordered, changeable, and allow duplicate values.
- List items are indexed, the first item has index [0], the second item has index [1] etc.
- use the
len()
function - List items can be of any data type i.e Str, bool, int, set,tuple etc.
- It is also possible to use the
list()
constructor when creating a new list. - Array Methods
append()
,clear()
,copy()
,count()
,extend()
,index()
,insert()
,pop()
,remove()
,reverse()
,sort()
.
-
the indented block starts after the
:
symbol. -
Comment start with
#
, multiline comment """ this is a comment """ -
Variables are containers for storing data values.
- Python has no command for declaring a variable.
- A variable is created the moment you first assign a value to it.
- Variables do not need to be declared with any particular type, and can even change type after they have been set.
- If you want to specify the data type of a variable, this can be done with casting.
- You can get the data type of a variable with the
type()
function. - String variables can be declared either by using
single
ordouble
quotes: - Variable names are case-sensitive.
- A variable name must start with a letter or the underscore character
- A variable name cannot start with a number
- A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variable names are case-sensitive (age, Age and AGE are three different variables)
- A variable name cannot be any of the [Python keywords].
- Multi Words Variable Names
- Camel Case
- Pascal Case
- Snake Case
-
Operator
is
ReturnsTrue
if both variables are the same objectx is y
is not
ReturnsTrue
if both variables are not the same objectx is not y
in
ReturnsTrue
if a sequence with the specified value is present in the objectx in y
not in
ReturnsTrue
if a sequence with the specified value is not present in the objectx not in y
Django Framework (Syllabus)
- (1) Introduction to Django
- (2) Difference between an App and Project.
- (3) What are Migrations and Why we do that.
- (4) Admin part (How to create Superuser in python).
- (5) What are Views in Django URL Routing.
- (6) What is Render and relative import.
- (7) A overview of settings file in Django.
- (8) How to configure Template.
- (9) What are models.
- (10) Models are Admin Linkup.
- (11) Modelform creation.
- (12) Form Validation.
- (13) What is Context in Django.
- (14) Form in a View.
- (15) Custom Form.
- (16) How to setup Email in our Projects.
- (17) Static Files and Serving Static Files in Django.
- (18) Bootstrap Grid System.
- (19) Idea of CSS and Blocks.
- (20) URL names as Links.
- (21) How to add Authentication in Django Project with help of Registration Redux module.
- (22) Authentication Links in Navigation Bar.
- (23) Add Login Form in Bootstrap.
- (24) Query Set Basics.
- (25) How to render images and Videos on our site.
Multithreading in Python
- (1) Multithreading with Python
- (2) What is multithreading?
- (3) Starting a New Thread
- (4) The Threading Module
- (5) Synchronizing Threads
Python Data Types
- (1) Numeric Types:-
int
,float
,complex
- (2) Text Type:-
Str
data type and string operations - (3) Making Type:-
dict
- (4) Set Type:-
set
,forzenset
- (5) Sequence Type:-
Tuple
,list
,range
- (6) Boolean Type:-
bool
- (7) Binary Type:-
bytes
,bytearray
,memoryview
- (8) None Type:-
noneType
Python programe flow control
-
(1) Conditional blocks using if, else and elif
- By default, statements in the script are executed sequentially from the first to the last. Nested if, elif, else Conditions also applied.
- Python uses the
if
keyword to implement decision control.- if [boolean expression]:
else
Condition- the
else
condition can be optionally used to define an alternate block of statements to be executedif
the boolean expression in theif
condition evaluates toFalse
.
- the
elif
Condition- Use the
elif
condition is used to include multiple conditional expressions after theif
condition or between theif
andelse
conditions. - The
elif
block is executedif
the specified condition evaluates toTrue
.- price = 100
- if price > 100:
- print("price is greater than 100")
- elif price == 100:
- print("price is 100")
- elif price < 100:
- print("price is less than 100")
- Use the
- Python uses the
- By default, statements in the script are executed sequentially from the first to the last. Nested if, elif, else Conditions also applied.
-
(2) Simple for loops in python
- In Python, the for loop is used for iterating over sequence types such as [list], [tuple], [set], [range], etc. Unlike other programming language, it cannot be used to execute some code repeatedly.
- for x in sequence:
- statement1
- statement2
- ...
- statementN
- for x in sequence:
- The execution of the
for
loop can bestop
andexit
using thebreak
keyword on some condition. - Use the
continue
keyword to skip the current execution and continue on the next iteration using the continue keyword on some condition. - For Loop with Else Block
- The
else
block can follow thefor
loop, which will be executed when the for loop ends.
- The
- In Python, the for loop is used for iterating over sequence types such as [list], [tuple], [set], [range], etc. Unlike other programming language, it cannot be used to execute some code repeatedly.
-
(3) For loop using ranges, string, list and dictionaries
-
(4) Use of while loops in python
- With the
while
loop we can execute a set of statements as long as a condition istrue
. - remember to increment i, or else the loop will continue forever in
while
loop. - The
while
loop requires relevant variables to be ready, in this example we need to define an indexing variable, i, which we set to 1. break
,continue
andelse
play same role in for loop, while loop.- i = 1
- while i < 6:
- print(i)
- i += 1
- With the
-
(5) Loop manipulation using pass, continue, break and else
-
(6) Programming using Python conditional and loops block
Python Func�ons , Modules And Packages
- (1) Organizing python codes using functions
- (2) Organizing python projects into modules
- (3) Importing own module as well as external modules
- (4) Understanding Packages
- (5) Powerful Lamda function in python
- (6) Programming using functions,modules & external packages
Python Object Oriented Programming – OOPS
- (1) Concept of class, object and instances
- Python is an object oriented programming language.
- Almost everything in Python is an object, with its properties and methods.
- A Class is like an object constructor, or a "blueprint" for creating objects.
- To create a class, use the keyword
class
- class MyClass:
- def init(self, name, age):
- self.name = name
- self.age = age
- def init(self, name, age):
- class MyClass:
- Objects can also contain methods. Methods in objects are functions that belong to the object.
- Object Methods
- Modify Object Properties
- Delete Object Properties
- Delete Objects
- To create a class, use the keyword
- (2) Constructor, class attributes and destructors
- (3) Real time use of class in live projects
- (4) Inheritance , overlapping and overloading operators
- (5) Adding and retrieving dynamic attributes of classes
- (6) Programming using Oops support
- Python Inheritance
Inheritance
allows us to define a class that inherits all the methods and properties from another class.Parent
class is the class beinginherited
from, also called base class.Child
class is the class that inherits from another class, also called derived class.
- Python Inheritance