Thursday 16 August 2018

Python:Basic Notes


Python:Basic Notes
===============

Size of a empty list is 72.


import sys
a =[]
Sys.getsizeof(a)


Format method is very important.


Input —is liking talking a python expression so type cast It.


in python function also I object oriented.
Write 10 functions in python its a object oriented code . 
For code to be object oriented in python we don’t need to write a class.

Duct typing in python.
a=10
dir(a)—— very important 
Emulating number types can be found in docs.python.


Finding type of a object
type(a)
— will give string ,list ,class and so on ..


Anything that has a. Label Is a object in python.
Variables are labels to objects.(just references)


Python is a complied interpreted language .
Compliers job is to check to syntax and indentation.


map function. ——works for a collection ..

To check path.
>>> import sys
>>> sys.path


For comparison two things sets are best !


All collections can get length and we can iterate over them .


Set is not indexable — remember …. Can perform .. remove.
Set to use only when you are performing comparison if tow comparison …


Request module is used for rest api.
Import request


Response  =response.get(“http://www.google.com/“)
Response 
Response.status.code
dir(response)


NOTE: — response module looks like  dictionary  implementation but not its  cases sensitive — dictionaries are case sensitive …


EVERY IDENTIFIES ARE KEYS IN A DICTONARIES IN PYTHON …
In python mostly dictionary is used ..


Zip function to combine two dictionaries 


Python:Lambda Expressions, Map, and Filter


Lambda Expressions, Map, and Filter

What are lambda functions in Python?

In Python, anonymous function is a function that is defined without a name.
While normal functions are defined using the def keyword, in Python anonymous functions are defined using the lambda keyword.
Hence, anonymous functions are also called lambda functions.

How to use lambda Functions in Python?

A lambda function in python has the following syntax.
lambda arguments: expression
Lambda functions can have any number of arguments but only one expression. The expression is evaluated and returned. Lambda functions can be used wherever function objects are required.

Example of Lambda Function in python

# Program to show the use of lambda functions
double = lambda x: x * 2

print(double(5))
# Output: 10
In the above program, lambda x: x * 2 is the lambda function. Here x is the argument and x * 2 is the expression that gets evaluated and returned.
This function has no name. It returns a function object which is assigned to the identifier double. We can now call it as a normal function. The statement
double = lambda x: x * 2
is nearly the same as

def double(x):
   return x * 2

Use of Lambda Function in python

We use lambda functions when we require a nameless function for a short period of time.

In Python, we generally use it as an argument to a higher-order function (a function that takes in other functions as arguments). Lambda functions are used along with built-in functions like filter()map() etc.

There are two built in functions, filter and map. Once we know about how these operate, we can learn about the lambda expression, which will come in handy.