A Python script is a file containing Python code that is meant to be executed directly by the Python interpreter. These scripts can perform a variety of tasks, such as automating repetitive tasks, processing data, or even developing web applications
Creating and Running a Python Script
Here’s how to create and run a simple Python script:
Create a Python Script:
# This is a simple Python script
print("Hello, World!")
Comments are used to explain code and make it more readable. They are ignored by the Python interpreter.
# This is a comment
print("Hello, World!") # This is an inline comment
"""
This is a
multi-line comment
"""
Indentation is crucial in Python. It indicates a block of code. Consistent use of spaces or tabs is required (PEP 8 recommends using 4 spaces per indentation level).
if x > 0:
print("x is positive")
if x > 10:
print("x is greater than 10")
else:
print("x is non-positive")