“Introduction to Python Programming” Available Units for Reading
Running First Python Program
This is the most basic Python program. This program uses the print() function to display output on the screen
print("Hello, World!")When you run this code, the output will be:
Hello, World!How to run it:
- Type IDLE in search bar of windows OS
- Click on IDLE Python and then Press ctrl +n
- Type the code in new file and run via f5
- First it will ask to Save the file , do it as
hello.py - Now you can make changes in the existing file or create new python coding files.
Python Syntax
Syntax refers to the rules that define how Python code must be written. Python has a very clean and readable syntax.
1. Case Sensitivity : Python is case-sensitive, which means these are treated as two different lines.
print("Hello")
print("hello")2. No Semicolons : In languages like C or Java, statements end with a semicolon (;). In Python, this is not required:
print("Hello")3. Statements and Lines : Each line usually represents one statement.
print("Hello")
print(6)Comments in Python
Comments are used to explain code and make it easier to understand. They are ignored by the Python interpreter. So in the output comment lines will not be shown.
1. Single-Line Comments
Use # for single-line comments:
# This is a comment
print("Hello")Output :
Hello2. Multi-Line Comments
Python doesn’t have a dedicated multi-line comment syntax, but you can use multiple # or triple quotes:
Using multiple # lines
# This is line 1
# This is line 2Using triple quotes
"""
This is a multi-line comment
or docstring
"""Why Comments Are Important ?
- It Improve code readability.
- It Help others understand your code.
- It is Useful for debugging.
- It Serve as documentation.
Indentation in Python
Indentation refers to the spaces at the beginning of a line of code. You will learn more about indentation when you learn more upcoming topics.
It is Wrong
print("Hello")It is Right
print("Hello")Why Indentation is Important
- Defines code blocks (like loops, conditions, functions)
- It Improves readability and makes code structured and clean.
- Without proper indentation, code will produce error.