Вы находитесь на странице: 1из 2

UNIT II DATA, EXPRESSIONS, STATEMENTS

Python interpreter and interactive mode; values and types: int, float, boolean, string, and list;
variables, expressions, statements, tuple assignment, precedence of operators, comments;
modules and functions, function definition and use, flow of execution, parameters and
arguments; Illustrative programs: exchange the values of two variables, circulate the values of
n variables, distance between two points.

Python interpreter and interactive mode:

Python has two basic modes: normal/Script and interactive.

Interactive mode is a command line shell which gives immediate feedback for each
statement, while running previously fed statements in active memory. As new lines are fed into
the interpreter, the fed program is evaluated both in part and in whole.

Interactive mode is a good way to play around and try variations on syntax.
On macOS or linux, open a terminal and simply type "python". On Windows, bring up the
command prompt and type "py", or start an interactive Python session by selecting "Python
(command line)", "IDLE", or similar program from the task bar / app menu. IDLE is a GUI which
includes both an interactive mode and options to edit and run files.
Python should print something like this:

$ python
Python 3.0b3 (r30b3:66303, Sep 8 2008, 14:01:02) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

The >>> is Python's way of telling you that you are in interactive mode. In interactive mode
what you type is immediately run. Try typing 1+1 in. Python will respond with 2. Interactive
mode allows you to test out and see what Python will do.

A sample interactive session:

>>> 5
5
>>> print(5*7)
35
>>> "hello" * 4
'hellohellohellohello'
>>> "hello".__class__
<type 'str'>

The normal /Script mode is the mode where the scripted and finished .py files are run in the
Python interpreter.

In script mode, Python doesn't automatically display results.

In order to see output from a Python script, we'll introduce the print statement. This statement takes
a list of values and prints their string representation on the standard output file. The standard output
is typically directed to the Terminal window.
print "PI = ", 355.0/113.0

Script files can be execueted using Python interpreter. Application program scripts can be of any
size or complexity.Script programs should be saved with extension of .py . eg. example1.py.
example1.py contains the following lines of code
print 65, "F"
print ( 65 - 32 ) * 5 / 9, "C"

The simplest way to execute a script is to provide the script file name as a parameter to the
python interpreter. In this style, we explicitly name both the interpreter and the input script.
Here's an example.

Command Line Execution


python example1.py

Output:
65 F
18 C
Values /Objects :

A value is one of the basic things like a word or a number that a program manipulates.

>>>2+3
>>>5

From the above expression , 2 and 3 is part of expression ,also it is value, the result 5 is the
value, and the string Hello World is also a value

We can use the words value and object interchangeably.

Objects are classified into different classes, or data types.

Types / Datatypes:

Every value in Python has a datatype. Since everything is an object in Python programming,
data types are actually classes and variables are instance (object) of these classes.

There are various data types in Python.

Вам также может понравиться