Blogger Themes

Search This Blog

www.embeddedstudy.com | Copyright © 2017 | All Rights Reserved | Nithin Pradeep . Theme images by Storman. Powered by Blogger.

Follow by Email

Popular KOZHI

Sponsor

Download

Blogger Tricks

FEATURED

What is an Embedded System?

An embedded system is a combination of hardware and software that is designed to carry out a certain task or tasks, meaning it has a s...

JOIN THE TEAM

Popular Posts

Wikipedia

Search results

Search This Blog

Social

More Links

Social

ad

ads

Thursday, 17 August 2017

Operators in Python




In todays session we will see some of the most important data types in Python and some Examples...

In previous examples we have seen how to use print ,If we are using python3 then print is a function, syntax is as follows.

print (arguments)

Let us see how to print in different ways.

Now let us see how to scan an input from user
ie to scan in string format:
variable=raw_input(arguments)
in python 3 raw_input is not available 
to scan in integer format type cast it in python:
variable=int(raw_input(arguments))  or  variable=input(arguments)
  
to print data type use print type(variable)
in python3 input function will read like string if not used the typecasting.
  • ASSIGNMENT 
*** Write a program to swap two elements
Ans:
       

If we dont know a perticular function duty use help(function)

                                         help(int),help(str)......



 OPERATORS

 ARITHMATIC OPERATORS

+   (Addition)
 -   (Subtraction) 
*    (Multiplication)
   (Division)
**   (Power of)
//    (Floor Division) -for removing decimal part after division
  

 RELATIONAL OPERATORS
 <   (Less than)
 >  (Greater than) 
=    (Assignment)
!=    (Not Equal to)
==   (Comparison)
<=    (Less than or equal to)
>=    (greater than or equal to)

LOGICAL OPERATORS
and - logical anding
or -  logical oring
 not - logical Noting

BITWISE OPERATORS
 (And)
 |  (Or) 
~    (Complement)
<<    (Left shift)
>>   (Right shift)


Python is very efficient in memory saving.every thing is treated as seperate object but we get same address for x and z also for y and k since their value is same.Every memory is allocated dynamically.
to find size of an object use : variable.__sizeof__()
MEMBERSHIP OPERATORS
 in , not in

In a list ie:-
l=[10,20,30,40]
10 in l will give true,10 not in l will give False
 
IDENTITY OPERATORS
 is ,is not
x=10
y=20
x is not y => True
x is y=> False
 In the next sections we will see more about Data Types in Python...
THANK YOU.. 

2 on: "Operators in Python"