What is python
What is Python: - Python is an interpreted, object-oriented, high-level programming language with dynamic semantics. Python was developed byGuido Van Rossum in the late eighties and early nineties at the National Research Institute for Mathematics and Computer Science in the
Netherlands.
Features of Python:-
Less line of codes than other languages (fast execution)
Platform independent
Open Source
Object Oriented
It supports functional and structured programming methods
It can be used as a scripting language or can be compiled to byte-code for building large applications
It provides very high-level dynamic data types and supports dynamic type checking
It supports automatic garbage collection
It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java
How to start the Python? First of all install the Python 2.7.12 on your system. After installation it will create a directory in C: drive named Python27. In Python27
there is a file python.exe. Copy the path of python.exe from address bar.
To set the path of python in “path” system variable:-
1.
Copy the path of python.exe from address bar.
2.
Right click on Computer then click on Properties.
3.
Click on Advanced System Settings then click on Environment Variables.
4.
Choose path variable and click on Edit button.
5.
Deselect the path and stuff a semicolon at last and paste the copied path.
6.
Now click on OK button.
First Python Program:-
Open the command prompt, type python and press enter key.
The python prompt will open. Now type the following code:-
print “Hello Python!”
press enter key it will display following output:-
Hello Python!
Make simple calculator using python:-
On command prompt make a directory PythonProgs using md command.
Then use cd command to open PythonProgs directory.
Now type notepad SimpleCalc.py. The notepad editor will open and type the following code:-
a=input(“Enter first number : ”)
b=input(“Enter first number : ”)
print “Summation = ”,(a+b)
print “Subtraction = ”(a-b)
print “Multiplication = ”(a*b)
print “Division = ”,(a/b)
Now save the file SimpleCalc.py and close the file.
Now at command prompt type python SimpleCalc.py it display the following output:-
Enter first number : 10
Enter second number : 5
Summation = 15
Subtraction = 5
Multiplication = 50
Division = 2
Decision Making Statements:-
Use of if statement:-if is a keyword which is used for decision making. The syntax of if statement is given below:-
if condition:
Statement 1
Statement 2
Notes:-In Python there is no need to used curly braces { }. In python we use indentation to make code
Comments
Post a Comment
Thank you for comment.