Learning-Day-02
Let's Learn Python
# Day-02
Environments of python coding:
1. Interactive mode.
2. script mode.
-----------------------------
1. interactive Mode
command prompt.
--> line by line (stmt by stmt execution)>
from command prompt, once developer gives a statement and
defined object, When he called the statement or object name,
output value will be returned on console.
Example:
>print("Hello-World !")
Hello-World !
>a=10 ( Press Enter )
>b=20
>c=a+b
>c ( Press Enter )
30
Advantage of interactive mode:
------------------------------
While developing logics for some programming tasks , initially
developer does not have entire blueprint of the program in mind.
Developer starts journey of coding with basic steps.
suppose, he has given statement1 and checks output.
then statement2 and checks output , then he gets some clue what to do
in its next step. similarly after completion of 15 statements,
he gets clue , what to do in 16th statement. By using this feature
complex logics can be easily built in interactive way with system.
2. Script Mode
--> All statements will be kept in a file with .py extension.
p1.py
>python p1.py
generally, we use interactive mode in development phase.
we use scripts in production.
----------------------------------------
Coding rules of Python.
-----------------------
There are 4 important Rules to Follow:
Rule:1
Each statement should start with column position 1.
print("Hello") #invalid because There is a Space while starting
print("Hello") #valid because there is no Space before Starting
______________________________________________________
Rule 2:
If a line is expecting sub statements, the line should end with
colon (:)
ex:
a=10
b=20
if a>b:
print(a, " is big")
else:
print(b, " is big ")
Example:
x = [10,20,30,40]
for i in x:
print(i)
# In any Loos we are using (:) instead of { opening and Closing }
______________________________________________________
Rule 3:
sub statement should be started in forwarded position
to parent statement
# invalid code
if a>b:
print(a, " is big ") # this Statement Started Without Indentation
else:
print(b, " is big ")
# Correct Code
if a>b:
print(a, " is big ") # This statement was started with Indentation
else:
print(b, " is big ")
------------------------------------------------------------------------------------------
a=10
b=25
c=30
if a>b:
if a>c:
print(a, " is big")
else:
:
:
______________________________________________________
Rule 4:
all sub statements of a parent , should be in same column position.
a=10
b=20
if a>b:
print(a, " is big ") # Sub-statement 1
print(b, " is small ") # Sub-statement 2
else:
print(b, " is big ")
print(a, " is small ")
-----------------------------------
Rule 1:
statement should start with col pos 1.
Rule 2:
If line expecting sub statements, it should end with colon
ex: if, for, while etc
Rule 3:
sub statement should start in forwarded pos to parent .
Rule 4:
All sub statements should be in same column position.
----------------------------------------------------
Any Doubts Regarding to All topics will be covered by the next session @ 27-June
To Download this File Click on the below link:
-----------------------------------------------------
Best Regards:
Venkata Sreeram