Python Execution Modes

ProficientOrbit avatar
ProficientOrbit
·
·
Download

Start Quiz

Study Flashcards

24 Questions

What is an advantage of using the interactive mode in Python?

It provides instant execution of individual statements.

What is the default file extension for Python scripts?

.py

What is a disadvantage of using the interactive mode in Python?

It does not allow for the saving of statements for future use.

What is the purpose of the 'Run' menu in IDLE?

To execute a Python script.

How can you create a Python script file in IDLE?

By clicking on 'File' -> 'New File' and saving it.

What is PyCharm?

A Python IDE.

What is the difference between interactive mode and script mode?

Interactive mode is used for single-line code, while script mode is used for multiple-line code.

What is a characteristic of working in script mode?

It allows for the creation of multiple lines of code.

What is a variable in Python?

An object stored in the memory

What is the purpose of a comment in Python?

To add a remark or note in the source code

What happens when a variable is assigned a value for the first time in Python?

The variable is implicitly declared and defined

What is the purpose of the assignment statement in Python?

To create a new variable and assign a specific value to it

What happens when a variable is used in an expression in Python?

The variable name is replaced with the variable's value

What is the significance of the # symbol in Python?

It is used to start a comment

What is the treatment of every value or data item in Python?

As an object that can be assigned to a variable or passed to a function as an argument

What is the requirement for using a variable in an expression in Python?

The variable must be assigned a value before it is used

What is the main function of the Python interpreter?

To run Python programs that are saved in files or interactively execute Python statements

What does IDLE stand for?

Integrated Development and Learning Environment

What is an IDE?

A software application that provides comprehensive facilities to computer programmers for software development

What is the function of the Python shell?

To execute Python commands or statements

What is the symbol >>> used for in the Python interpreter?

To indicate that the interpreter is ready to take instructions

What is the purpose of the Python IDLE?

To simplify the process of writing, executing, and testing programs

What is the difference between interactive mode and script mode?

Interactive mode is used to execute Python statements, while script mode is used to write Python programs

What is the name of the website where you can use an online Python interpreter?

Study Notes

Execution Modes

  • There are two ways to use the Python interpreter: Interactive mode and Script mode.
  • Interactive mode allows execution of individual statements instantaneously, and is convenient for testing a single line of code for instant execution.
  • Script mode allows us to write more than one instruction in a file called a Python source code file that can be executed.

Interactive Mode

  • To work in interactive mode, we can simply type a Python statement on the >>> prompt directly.
  • As soon as we press enter, the interpreter executes the statement and displays the result(s).
  • In interactive mode, we cannot save the statements for future use and have to retype the statements to run them again.

Script Mode

  • In script mode, we can write a Python program in a file, save it, and then use the interpreter to execute it.
  • Python scripts are saved as files with extension “.py”.
  • By default, the Python scripts are saved in the Python installation folder.
  • There are two ways to create a script file: create a python file (.py) from IDLE (“File” ➔”New File”), and save it, or create a Python file (.py) using an editor like Notepad++, save it, and then open it directly from IDLE (“File” ➔”Open”).

Installing PyCharm

  • PyCharm is one of the best IDEs for Python.
  • When you install the Python language on your computer, one of the items that is installed is the Python interpreter.
  • The Python interpreter can run Python programs that are saved in files or interactively execute Python statements that are typed at the keyboard.
  • Python comes with a program named IDLE that simplifies the process of writing, executing, and testing programs.

Python IDE/IDLE

  • Python IDLE (Integrated Development and Learning Environment) is an integrated development environment for Python, which has been bundled with the default implementation of the language.
  • IDLE provides comprehensive facilities to computer programmers for software development.
  • Most modern IDEs have intelligent code completion.

Installing Python and PyCharm IDE

  • To install Python, go to www.python.org and click on “Downloads” link at the top of the page, then click on “Download Python 3.11.2”.
  • After installation, the Python interpreter is installed on your computer to run and execute python programs.

Running Python

  • The interpreter is also called Python shell.
  • A sample screen of Python interpreter (or shell) is shown in the following figure.
  • The symbol >>> is the Python prompt, which indicates that the interpreter is ready to take instructions.

Variables in Python

  • A variable in Python refers to an object — an item or element that is stored in the memory.
  • Value of a variable can be a string (e.g., ‘b’, ‘Global Citizen’), numeric (e.g., 345) or any combination of alphanumeric characters (CD67).
  • In Python, we can use an assignment statement to create new variables and assign specific values to them.
  • Variable declaration is implicit in Python, means variables are automatically declared and defined when they are assigned a value the first time.
  • Variables must always be assigned values before they are used in expressions, otherwise, it will lead to an error in the program.
  • Wherever a variable name occurs in an expression, the interpreter replaces it with the value of that particular variable.

Comments in Python

  • Comments are used to add a remark or a note in the source code.
  • Comments are not executed by the interpreter.
  • In Python, a comment starts with # (hash sign).
  • Everything following the # till the end of that line is treated as a comment and the interpreter simply ignores it while executing the statement.

Everything is an Object

  • Python treats every value or data item whether numeric, string, or other type as an object in the sense that it can be assigned to some variable or can be passed to a function as an argument.

Learn about the two ways to use the Python interpreter: Interactive mode and Script mode. Understand how to execute individual statements and write Python source code files.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free

More Quizzes Like This

Python Mastery Quiz
5 questions

Python Mastery Quiz

SatisfactoryHyena avatar
SatisfactoryHyena
Python Basics Quiz
3 questions

Python Basics Quiz

VerifiableDiopside avatar
VerifiableDiopside
Python: Compiled vs Interpreted
40 questions
Python Installation on Windows Tutorial
5 questions
Use Quizgecko on...
Browser
Browser