Day 1
Python 3 uses 3 tools
to execute: IDLE, Pycharm and Notebook. These are opensource tools and can be
downloaded from the internet.
Small Pyhton example
in IDLE. Use fn+F5 to run the program
print (“Hello”)
Hello
Another example
a=5
b=10
c=a+b
print©
15
Another example
a=5
b=10
c=a+b
print(“sum of”,a,”and”,b,”is”,c)
sum of 5 and
10 is 15
so in the above
example, we notice that variable is not in quotes.
String is in Double
quotes “ ”
To coordinate we use
comma ,
Any number
without decimal value is integer (INT)
Any number
with decimal value is Float
String can
be written in single, double or triple quotes
‘ ‘ “ “ ‘’’ ‘’’
Boolean=
true or false
To find out what type
of value is either INT or float we use
type() command
Example
a=5
b=10
c=a+b
print(c)
print(c,type(c))
15 <class
'int'>
To check the address
of the value in memory we use id() command
print(Id(a))
1815438496
For multi-line comment
use ‘’’ ‘’’
If you have single
quote in the string you can use only double quotes within the string and vice
versa
print( ‘hello,”this is
abhishek”laptop’)
Helllo,”this
is abhisheks”laptop
You can use same
single quote within the sting too but for that you need to use \’
print('Helllo,this is
abhishek\'s laptop')
Helllo,this
is abhishek's laptop
Now we will use
pycharm tool. To run the function we need CTL+shift+fn+F10. Create a new
project and start working.
There are 7 types of
operators in Python:
1) Arithmetic Operator
2) Relational Operator
3) Logical Operator
4) Bitwise Operator
5) Assignment Operator
6) Identical Operator
7) Membership Operator
Arithmetic
Operator
Key functions are:
+
-
X
/ (division)
%
//(flow division)
Xx( (exponential)
Example
a=19
b=4
c=a+b
d=a-b
e=a*b
f=a/b
g=a%b
h=a//b
i=2**4
print(c,d,e,f,g,h,i)
b=4
c=a+b
d=a-b
e=a*b
f=a/b
g=a%b
h=a//b
i=2**4
print(c,d,e,f,g,h,i)
The output is
23 15 76 4.75 3 4 16
So we see the output c=a+b=23 d=a-b=15 e=a*b=76 f=a/b=4.75 g=a%b=3 h=a//b=4
i=2**4=16
Relational Operator
<
>
>=
<=
== (equals to)
!= (not equals to)
These are used with conditional statement
Logical Operator
Logical OR (or)
Logical AND (and)
Logical Not (not)
These are also used with conditional straments
Here just remember at this stage, False is zero and
true is other than Zero
If a=5, b=8
Then C=a or b
=5 or 8
=5
Id d= a and b
=5 and 8
=8
Bitwise Operator
Its hardly used in Python. So there wont be any
focus on it
1)
Bitwise OR (I)
2)
Bitwise AND (&)
3)
Bitwise X-OR(^)
4)
Bitwise Leftshift(<<)
5)
Bitwise Rightshift(>>)
6)
Bitwise Complement (~)
Assigment Operator
=
+=
-=
X=
/=
%=
//=
Xx=
A+=b means a=a+b
Identity Operator
Only 2 functions
Is
Is not
a=10 b=20, c=10
print(a is b)=> false
print(a is c)=> True
Membership Operator
Only 2 functions
In
Not in
A=[10,20,30,40,50]
Print(30 in a)=> True

No comments:
Post a Comment