• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
PythonForBeginners.com

PythonForBeginners.com

Learn By Example

  • Home
  • Learn Python
    • Python Tutorial
  • Categories
    • Basics
    • Lists
    • Dictionary
    • Code Snippets
    • Comments
    • Modules
    • API
    • Beautiful Soup
    • Cheatsheet
    • Games
    • Loops
  • Python Courses
    • Python 3 For Beginners
You are here: Home / Basics / Using the Python Interpreter

Using the Python Interpreter

Author: PFB Staff Writer
Last Updated: May 25, 2020

Python interpreter

The Python interpreter is usually installed in /usr/local/bin/python on machines
where it is available;

Putting /usr/local/bin in your Unix shell’s search path makes it possible to
start it by typing the command: python to the shell.

When you start the Python in interactive mode, it prompts for the next command,
usually three greater-than signs (“>>> “).

The interpreter prints a welcome message stating its version number and a
copyright notice before printing the first prompt, eg:

Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> the_world_is_flat = 1
>>> if the_world_is_flat:
...     print "Be careful not to fall off!"
...

Python Interactively

When you use Python interactively, it is handy to have some standard commands
executed every time the interpreter is started.

You can do this by setting an environment variable named PYTHONSTARTUP to the
name of a file containing your start-up commands.

This is similar to the .profile feature of the Unix shells.

To do that, add this line to your .bashrc file:
>> export PYTHONSTARTUP=$HOME/.pythonstartup

Create (or modify) the .pythonstartup file and put your python code in there:

import os
os.system('ls -l')

To exit from the Python interactive prompt, we’ll hit Ctrl+D (in Linux)

See Pythons official documentation for more information.

Related

Recommended Python Training

Course: Python 3 For Beginners

Over 15 hours of video content with guided instruction for beginners. Learn how to create real world applications and master the basics.

Enroll Now

Filed Under: Basics Author: PFB Staff Writer

More Python Topics

API Argv Basics Beautiful Soup Cheatsheet Code Code Snippets Command Line Comments Concatenation crawler Data Structures Data Types deque Development Dictionary Dictionary Data Structure In Python Error Handling Exceptions Filehandling Files Functions Games GUI Json Lists Loops Mechanzie Modules Modules In Python Mysql OS pip Pyspark Python Python On The Web Python Strings Queue Requests Scraping Scripts Split Strings System & OS urllib2

Primary Sidebar

Menu

  • Basics
  • Cheatsheet
  • Code Snippets
  • Development
  • Dictionary
  • Error Handling
  • Lists
  • Loops
  • Modules
  • Scripts
  • Strings
  • System & OS
  • Web

Get Our Free Guide To Learning Python

Most Popular Content

  • Reading and Writing Files in Python
  • Python Dictionary – How To Create Dictionaries In Python
  • How to use Split in Python
  • Python String Concatenation and Formatting
  • List Comprehension in Python
  • How to Use sys.argv in Python?
  • How to use comments in Python
  • Try and Except in Python

Recent Posts

  • Count Rows With Null Values in PySpark
  • PySpark OrderBy One or Multiple Columns
  • Select Rows with Null values in PySpark
  • PySpark Count Distinct Values in One or Multiple Columns
  • PySpark Filter Rows in a DataFrame by Condition

Copyright © 2012–2025 · PythonForBeginners.com

  • Home
  • Contact Us
  • Privacy Policy
  • Write For Us