Table of Contents
TogglePython is celebrated for its easy-to-read syntax, making it an excellent language for beginners. It shares some similarities with languages like Perl, C, and Java but has unique features that set it apart. Let’s explore the basics of Python syntax and understand how to write a simple Python program.
Python allows you to write and execute programs in two modes: Interactive Mode and Script Mode. Here’s how you can get started with both:
In Interactive Mode, you can execute Python commands directly in the terminal. For example:
$ python3
>>> print("Hello, World!")
Hello, World!
In Script Mode, you write your program in a file (e.g., test.py) and execute it. Example:
$ python3 test.py
Hello, World!
Python identifiers are used to name variables, functions, classes, and more. Here are the key rules:
manpower and Manpower are different.Python uses indentation to define code blocks, instead of braces ({ }). Indentation is mandatory and ensures code readability. Example:
if True:
print("True")
else:
print("False")
Comments in Python help make the code more readable. Use a hash (#) for single-line comments or triple quotes (''') for multi-line comments.
# Single-line comment
print("Hello, World!") # Inline comment
'''
This is a multi-line
comment.
'''
Start your Python journey today and master programming with ease!
