Python Input and Output

Print: it is an output statement to print the string on output device

Syntax: print(“string”/var);

 

Programe to print the name and address

Test.py

Print("vision”);
Print(“vuyyuru”);
Print(“521165”);

 

Compile & execute

Python test.py

Assignments can be done on more than one variable "simultaneously"

Program on multiple assignments

a,b=3,4;
print(a,b);

Number Type Conversion
int(x)               to convert x to a plain integer.
long(x)            to convert x to a long integer.
float(x)            to convert x to a floating-point number.
complex(x)      to convert x to a complex number with real part x and imaginary part zero.
complex(x, y)  to convert x and y to a complex number with real part x and imaginary part y. x and y are numeric expressions

Input: It is an input statement to read the values from the input device

Syntax:            var=input(“string”)
Ex:                   a=input(“enter number”);
Find the sum of 2 numbers

# sum of 2nos
a=input("Enter first number");
b=input("Enter second number");
c=int(a)+int(b);
print("Sum of 2 nos",c);

 

 

For
Online Classes

Contact Us: 9885348743