Class-2 & 3 Python
Topic:
How to Execute Python Program
Comment in Python
Output Statement
Input Statement
➡️How To Execute Python Program :-
1. There Are Three Way to Execute Python Program.
1. Using Python IDLE.
2. Using Python Shell.
3. Directly From System Prompt (CMD).
1. C:\ user\user name \ Drive:
2. Drive:\> cd folder name
3. Drive:\ folder name > Python file_name.py
4. Output :- --------
➡️Write First Python Program For Addition Of Two Number
➡️Comment In Python :-
Comment are those statement in the program which are only read by Programmer,
Computer never read the Comment statement.
➡️There are Two Types Of Comment:-
1. Single Line Comment:-
1. Syntax :- # Comment Statement ………….
2. Multiline Comment :-
Official Python does not support multiline comment but we can use multiline comment with
the help of multiline string.
I.e…
‘’’
Line 1 Statement
Line 2 Statement
Line 3 Statement ‘’’
OR
“””
Line 1 Statement
Line 2 Statement
Line 3 Statement “””
➡️Output:- To display anything on the output screen we need Output statement.
In Python Print() work as a output statement.
⇒ How to Print any message on the Output screen ?
Syntax:- Print(“Hello world”)
e.g:- print(“Saurav”) #output Saurav
print(“Rahul”) Rahul
NOTE:- Print change line Automatically
If We don’t want to change Line after print statement then we use end keyword.
e.g:- print(“Rahul”,end=” “) #output
print(“Saurav”,end=” “) RahulSauravRamesh
print(“Ramesh”,end=” “)
⇒ In Python we want to Print same statement number of times.
Print(5 * “Hello) #Output Hello Hello Hello Hello Hello
⇒ Print Variable value using Print():-
a=10
print(a) #Output 10
b=19
c=78
print(a,b,c) #Output 10 19 78
print(a,b,c,sep=”_”) #Output 10_19_78
print(a,b,c,sep=”…..”) #Output 10…..19…..78
➡️Input():- This function takes user input from keyboard in the form of string. It also use
to print prompt message.
eg. x = input(“enter name:”) #Output enter name: Rahul kumar
Print(type(x), x) #Output <class = “str”> Rahul kumar
y = input(“enter any number:”) #Output enter any number: 467
Print(type(y), y) #Output <class = “str”>467
z = input(“enter any decimal number:”) #Output enter any decimal number: 3.14
Print(type(z), z) #Output <class = “str”>3.14
⇒ Input method only accepts string data either the value of data is numerical or decimal.
If we accept user input as a string value then there is no need to convert the value into string
type. But , if we want the python to accept data in Integer or float form then we need to
convert the input value into particular type.
For this Purpose, we have method:
1. String to Integer
S = “123”
Num = int(S)
b. String to float
S = “3.14”
F = float(S)
c. String to Boolean
S = “True”
B = bool(S)