1 0 Introduction
1 0 Introduction
Table of contents
What is Python?
Install Python
Create and Run Your First Python Program
Run Python Using IDLE
Run Python on Command Line
Execute Python File
Syntax and Indentation in Python
Using Blank Lines in code
End-of-Line to Terminates a Statement
Semicolumn to Seperate Multiple Statements
Indentation
Next Steps
What is Python?
Python is a general-purpose, high-level, interpreted,
object-oriented programming language used for a wide
variety of applications.
Install Python
It may be possible that some PCs and Macs will have Python
already installed. You can check which version of Python is
installed before proceeding to the installation.
python --version
Let’s open the command line or terminal and type the below
command to check the version of Python.
python --version
print('Hello, World')
Run
Output:
Hello, World
Open any text editor and type the below code in it, and
save it as a hello.py
print('Hello, World')
Run
Now, open the terminal or command line use the below
command to execute the message.py. You need to change the
directory where this file is present before executing it.
python message.py
Here python is the command and message.py is the file name you
want to execute.
Run
Python script using command line
You should get the following output.
Hello, World
Example
a = 20
addition = 10 + 20 + \
30 + 40 + \
50 + 60 + 70
print(addition)
# Output: 280
Run
# statement 3
print('Area of rectangle:', l * b)
Run
Most Python style guides don’t recommend adding multiple
statements on a single line, though occasionally, it
improves readability.
Indentation
Python indentation tells a Python interpreter that the
group of statements belongs to a particular block of code.
The indentation makes the code look neat, clean, and more
readable.
num1 = 50
num2 = 100
if num1 > num2:
print(num1, 'is greater than', num2)
elif num2 > num1:
print(num2, 'is greater than', num1)
else:
print('Both numbers are equal')
Run
Indentation in Python
If one code block is nested in another block, the child
code block should separate by 4 spaces from the parent code
block.