- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
How do we use Python in script mode?
Python is a high level programming language that helps a user to run a program and integrate systems more efficiently; as it executes a program in comparatively fewer lines of code. In this programming language, a code can be run in two ways−
Interactive mode, and
In this article, we will learn how to execute a python code in a script mode.
Python in Script Mode
A script mode in Programming languages is nothing but putting all the lines of code in a python program into a file, also known as a script, and using Python to run the file. Python in script mode can be run in various applications containing Python IDE; and also through a Terminal or Command Prompt.
In applications supporting Python, the scripts can be created and executed in the environment itself.
However, to execute a Python code in script mode using command line, one must follow the following command syntax −
Here, filename.py is just a placeholder for the file containing the Python lines of code.
Let us see an example to execute a Python code in a file, through the Command Prompt in Windows.
Assume we have a Python code in a file named ‘test.py’ –
#!/usr/bin/python print ("Hello World")
Make sure your system has python installed in it before executing the following command to execute the ‘test.py’ file −
The output is displayed as follows −
- Related Articles
- How do we use Python in script mode?
- How do we use Python in interactive mode?
- How do we use double quotation in Python?
- How do we display a script in HTML?
- Why do we use random.seed() in Python?
- Why do we use pandas in python?
- How do we use re.finditer() method in Python regular expression?
- How do we use equivalence (“equality”) operator in Python classes?
- How do we use easy_install to install Python modules?
- How do we use Python Regular Expression named groups?
- How do we use runOnUiThread in Android?
- How do we use file.readlines() to read multiple lines using Python?
- How do we use a delimiter to split string in Python regular expression?
- Why do we use re.compile() method in Python regular expression?
- When do we use crosstab and pivot_table in Python Pandas?
- How do we use # in jQuery Attribute Selector?