Thursday, July 7, 2016



Python Operators


Doing some operations on values that is through operator.operator is a symbol which  is do some operations on values and gives the output.

The values are known as Operands.


  • Operand operations(+,-,*,/) operand output operation(=) operand  


    Like:
1 + 2 = 3


  • Here 1 and 3 are Operands and  + (plus) ,= (equal) signs are the operators. They generate the output 9.


Python have some operators :


Let's know about python operators..

List of operators :

1) Arithmetic Operators.
2) Relational Operators.
3) Assignment Operators.
4) Logical Operators.
5) Membership Operators.
6) Identity Operators.
7) Bitwise Operators.

Let's know about in detail....

1) Arithmetic Operators:



  • // (Double forward slash sign) It Perform Floor division(gives integer value after division)


Like :
5 // 2 = 2


  • + (Plus sign)  It is use to perform  an addition.

Like :
5 + 2 = 7


  • - (Minus sign) It is use to perform subtraction


Like :
5 - 2 = 3

  • * (star sign) It is use to perform multiplication.


Like :
5 * 2 = 10


  • / (single forward slash sign) It is use to perform division


Like :
5 / 2 = 2.5


  • % (Modulus sign) To return remainder after division(Modulus)


Like :
10 % 3  = 1


  • ** (Two star sign) It is use to perform exponent(raise to power)


Like :
3**3  = 27




2) Relational Operators :



  • < Less than :

Like :
1<2
Output : True


  • > Greater than :


Like :
1<2
Output : False


  • <= Less than or equal to :


Like :
1<=1
Output : True


  • >= Greater than or equal to :


Like :
10>=5
       Output : True


  • == Equal to :

Like :
1<2
Output : False


  • != Not equal to :

Like :
1!=2
Output : True

  • < > Not equal to(similar to !=) :


Like :
        1< >2
Output : True
 
 3) Assignment Operators :



  • = Assignment :

Like :
a = 10
print a
Output : 10

  • /= Divide and Assign : 


Like :
a=10
a/=2
Output : 5

  • += Add and assign :


Like :
a=10
a+=2
Output : 12


  • -= Subtract and Assign :


Like :
                 a=10
                 a-=2
Output : 8

  • *= Multiply and assign :


Like :
a=10
a*=2

Output : 20


  • %= Modulus and assign :


Like :
a=10
a%=3

Output : 1


  • **= Exponent and assign :


Like :
a=5
a**=2
Output : 25


  • //= Floor division and assign


Like :
a=25
a//=2
Output : 12

4) Logical Operators:

  • and : Logical AND(When both conditions are true output will be true)
  • or : Logical OR (If any one condition is true output will be true)
  • not : Logical NOT(Compliment the condition i.e., reverse)

5) Membership Operators:


  • in : Returns true if a variable is in sequence of another variable, else false.
  • not in : Returns true if a variable is not in sequence of another variable, else false.


6) Identity Operators :

  • is   : Returns true if identity of two operands are same, else false
  • is not : Returns true if identity of two operands are not same, else false.


Wednesday, July 6, 2016

Python Literals


Literals can be defined as a data that is given in a variable or constant.

Let's know about python literals


1) String literals:

String literals can be written between quotes. We can use both single as well as double                       quotes for a String.

Like:

"Python" , 'literal','12'

Types of Strings:

Python have a two types of string:

i) Single line String :  Strings that are terminated within a single line are known as Single                       line Strings.

Like:
                            var1='singlelinestring'
 
ii) Multi line String : A piece of text that is spread along multiple lines is known as                                  Multiple line String.

There are two ways to create Multiline Strings:

a) Adding black slash at the end of each line.

like :

         var1='multiline\
 string'
output : 'multilinestring'
 

b) Using triple quotation marks :

like :

var1='''this
is
multiline
string'''

print var1

output :
this
is
multiline
string



2) Numeric literals:

Numeric Literals are immutable. Numeric literals can belong to following four different                     numerical types.

a) Int(signed integers) : Numbers( can be both positive and negative) with no fractional                         part.

b) Long(long integers) : Integers of unlimited size followed by lowercase or uppercase L

c) float(floating point) : Real numbers with both integer and fractional part.

d) Complex(complex) : In the form of a+bj where a forms the real part and b forms the                            imaginary part of complex number.

3) Boolean literals : A Boolean literal can have any of the two values: True or False.

4) Special literals : Python contains one special literal that is None.None is used to specify to                 that field that is not created. It is also used for end of lists in Python.

like :
val1=None
print val1
output :
None

5) Literal Collections : Collections such as tuples, lists and Dictionary are used in Python.

List:

  • List contain items of different data types. Lists are mutable  modifiable.
  • The values stored in List are separated by ,(commas) and enclosed within a [] (square brackets). We can store different type of data in a List.
  • Value stored in a List can be retrieved using the slice operator([] and [:]).
  • The + (plus) sign  is the list concatenation and asterisk(*) is the repetition operator.


Tuesday, July 5, 2016

Python Identifiers



  • The fundamental building blocks in a program known as identifier.
  • These can be variables ,class ,object ,functions , lists , dictionaries etc.


There are certain rules defined for naming 


    1. An identifier is a long sequence of characters and numbers.

    2. No special character except _ (underscore)  can be used as an identifier.

    3. Identifier name can not same as keyword.

    4. using case is significant because python is case sensitive.

    5. First character of identifier can not be a digit.It must be start with character or _ (underscore).

Monday, July 4, 2016

Python Keywords


Keywords :
It is a special reserve words which have a special meaning for                                                                 Interpreter/compiler.
Each keywords have a specific operations and a special meaning.

Let's Know about python Keywords 


List of keywords used in python are:


  • True : True and False are truth values in Python. They are the results of comparison operations or logical (Boolean) operations in Python.
  • False : True and False are truth values in Python. They are the results of comparison operations or logical (Boolean) operations in Python.
  • None : None is a special constant in Python that represents the absence of a value or a null      value. It is an object of its own datatype, the NoneType.
  • and : and is the logical operator in Python. and will result into True only if both the operands are True.
  • as : as is used to create an alias while importing a module. It means giving a different name     (user-defined) to a module while importing it.
  • asset : assert is used for debugging purposes. While programming, sometimes we wish to know the internal state or check if our assumptions are true. assert helps us do this and find  bugs more conveniently. assert is followed by a condition. If the condition is true, nothing happens. But if the condition is false, AssertionError is raised. 
  • def : def is used to define a user-defined function.
  • class : class is used to define a new user-defined class in Python.
  • continue : continue are used inside for and while loops to alter their normal behavior. continue  causes to end the current iteration of the loop, but not the whole loop.
  • break : break is used inside for and while loops to alter their normal behavior. break will end   the smallest loop it is in and control flows to the statement immediately below the loop.
  • if : if is used for conditional branching or decision making.
  • else : else is used for conditional branching or decision making.
  • elif : elif is used for conditional branching or decision making.
  • finally : finally is used with try…except block to close up resources or file streams. Using        finally ensures that the block of code inside it gets executed even if there is an unhandled exception.
  • del : del is used to delete the reference to an object. Everything is object in Python. We can   delete a variable reference using del.
  • except : except is used with exceptions in Python. Exceptions are basically errors that suggests something went wrong while executing our program.    
  • global : global is used to declare that a variable inside the function is global (outside the function).
  • for : for is used for looping. Generally we use for when we know the number of times we want to loop. In Python we can use it with any type of sequence like a list or a string. 
  • from : from…import is used to import specific attributes or functions into the current namespace.
  • import : import keyword is used to import modules into the current namespace. 
  • raise : raise is used with exceptions in Python.We can raise an exception explicitly with the raise keyword. 
  • try : try is used with exceptions in Python.
  • or : or is the logical operator in Python. and will result into True only if both the operands are True.
  • return : return statement is used inside a function to exit it and return a value. If we do not return a value explicitly, None is returned automatically.
  • pass : pass is a null statement in Python. Nothing happens when it is executed. It is used as a placeholder.
  • nonlocal : The use of nonlocal keyword is very much similar to the global keyword.  it is used to declare that a variable inside a nested function (function inside a function) is not local to it, meaning it lies in the outer inclosing function.
  • in : in is used to test if a sequence (list, tuple, string etc.) contains a value. It returns True if the value is present, else it returns False.
  • not : not is the logical operator in Python. and will result into True only if both the operands are True.
  • is : is is used in Python for testing object identity.is is used to test if the two variables refer to the same object. It returns True if the objects are identical and False if not.
  • lambda : lambda is used to create an anonymous function (function with no name). It is an inline function that does not contain a return statement.It consists of an expression that is evaluated and returned. 





Sunday, July 3, 2016

Basic Fundamentals:


The basic fundamentals of Python like :

i)Tokens and their types.

ii) Comments

a)Tokens:



  • A reserved word known as a tokens that can be defined as punctuator mark.
  • Token is the smallest unit inside the given program.
  • There are following tokens in Python:


Keywords.
Identifiers.
Literals.
Operators.

Tuples:


  • Tuple is another form of collection where different type of data can be stored.
  • It is similar to list where data is separated by ,(commas). Only the difference is that list               uses [] (square bracket) and truple uses ()(parenthesis).
  • Tuples are enclosed in parenthesis and cannot be changed.



Eg:

tuple=('python',200,70.5,'basic')
tuple1=('fundamentals',20)

Above is a declaration of truple there are tow variable in truple truple and tuple1.

             Outputs :


  • when you write in the console truple then it display all truple value.


   like :
tuple
('python',200,70.5,'basic')


  • when you want a specific position data and after position all data then write a variable name and its value position and after that put a : (colon) sign 


like :
tuple[2:] (truple(name of the variable)[2(it is a position of variable):(it is like a * after                           position all data print)])
(70.5, 'basic')


  • when you know the what position data you want that time use this variable name [ position of data ]


like :
   tuple1[0]
   'fundamentals'

collaboration of two truples 


  • using +(plus)sign you can collaborate two or more truples.


like :
tuple+tuple1
('python',200,70.5,'basic','fundamentals',20)


Dictionary:

Dictionary is a collection which works on a key-value pair.
It works like an associated array where no two keys can be same.
Dictionaries are enclosed by {} (curly braces) and values can be retrieved by []                                    (square bracket).

Syntax :
variable name =(equal sign) {'key':(colon)'value }

Like :
Deceleration : dictionary={'name':'abc','id':500,'dept':'ec'}
Input  : dictionary
Output :{'dept': 'ec', 'name': 'abc', 'id': 500} (It display output after sorting)

Input : dictionary.keys() (if you want only keys then write a variable name .(dot) keys())
Output: ['dept', 'name', 'id']
Input : dictionary.values() (if you want only values then write a variable name .(dot) values())
Output: ['ec', 'abc', 500]


ii) Comments :


python support two types of comments.

1) single line comments :

single line comments start with # sign.

like #comments
2) Multi line Comments :

Multi lined comment can be given inside triple quotes.

like :
'''multi line
comment '''

Saturday, July 2, 2016


Python variables



  • Name of the memory location where data store is known as a variable.Space allocate in the memory when variable is stored.


How to assigning values to variable ??



  • In the python not need to declare variable explicitly.when assign a value to the variable it is declared automatically.



  • In the python assignment is done using  the = (equal) operator.


Eg :
A=5

Name='Python'

Empsal=1256.56

print A

print Name

print Empsal

Output :
5
Python
1256.56


        Multiple Assignment using python.



  • At a time multiple assignment do in python.


let's know about how to do multiple assignment using python. 


There are tow ways do a multiple assignment in python.

(1) Assigning single value to multiple variable :


Eg :
a=b=c=10

print a
print b
print c

Output :
10
10
10

(2) Assigning multiple values to multiple variable :


Eg :
a,b,c=1,2,3
print a
print b
print c

Output :
1
2
3

This is also known as parametrized variable because first value assign to first variable second is for second.

Friday, July 1, 2016

Python Applications


Let us know about which type of application we make in python.



  • Console Based Application : we make a console based application using python. For example: IPython.
  • Web Applications : python is also use for making a web based application. this are the application which is made in python PythonWikiEngines, Pocoo, PythonBlogSoftware etc.

  • Applications for Images : Using python we can make a application for images. Like a image processing ,VPython, Gogh, imgSeek etc.

    • Audio or Video based Applications : using python we make a audio or video application.python provide a multimedia section. Some of real applications are: TimPlayer, cplay etc.


    • 3D CAD Applications :Using python we can make a 3D cad applications. On of the real application is Fandango which provides full features of CAD and it is made in python.


    • Enterprise Applications : In the python we can make a application which is used in single organization or enterprise. Like a OpenErp, Tryton, Picalo etc.

    This are the applications which can be developed using Python.