Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Python is a high-level, interpreted, interactive and object-oriented scripting language.

Scripting language is basically a language where instructions are written for a run time
environment.

Difference between Interactive mode and Script mode


Interactive mode
 Itis used when an user wants to run one single line or one block of code.
 It runs very quickly and gives the output instantly.

Script Mode
 It is used when the user is working with more than one single code or a block of
code.
 It takes more time to compile. In this mode, one can simply write all the lines of code
in a text file.

Basic Data Type

A variable can hold different types of values. For example, a person's name must be stored as
a string whereas its id must be stored as an integer.

Python provides various standard data types that define the storage method on each of them.
The data types defined in Python are given below.
1. Numbers
2. String
3. List
4. Tuple
5. Dictionary

Numbers

Number stores numeric values. Python creates Number objects when a number is assigned to
a variable. Python supports 4 types of numeric data.
1. Integers
a) int (signed integers like 10, 2, 29, etc.)
b) long (long integers used for a higher range of values like 908090800L, -
0x1929292L, etc.)
c) bool (The two objects representing the values Fals and True are the only Boolean
objects)
2. float (float is used to store floating point numbers like 1.9, 9.902, 15.2, etc.)
3. complex (complex numbers like 2.14j, 2.0 + 2.3j, etc.)

String

The string can be defined as the sequence of characters represented in the quotation marks. In
python, we can use single, double, or triple quotes to define a string.

List

The list can contain data of different types. The items stored in the list are separated with a
comma (,) and enclosed within square brackets [].

Tuple

A tuple is a read-only data structure as we can't modify the size and value of the items of a
tuple.

Dictionary

Dictionary is an ordered set of a key-value pair of items. It is like an associative array or a


hash table where each key stores a specific value.
Operator: An operator is a symbol which specifies a specific action.
Operand: An operand is a data item on which operator acts.

Arithmetic Operators
Unary Operators – The operators that acts on one operand are referred to as Unary Operator.
Binary Operator – Operators that act upon two operands are referred to as Binary Operator.

Assume variable a holds 2 and variable b holds 3, then


Operator Description Example

+ Addition Adds values on either side of the operator. a + b = 5

- Subtraction Subtracts right hand operand from left hand operand. a – b = -1

* Multiplication Multiplies values on either side of the operator a * b = 6

/ Division Divides left hand operand by right hand operand b / a = 1

% Modulus Divides left hand operand by right hand operand and b % a = 1


returns remainder

** Exponent Performs exponential (power) calculation on operators a**b =8


// Floor Division - The division of operands where the result 9//2 = 4
is the quotient in which the digits after the decimal point 9.0//2.0 =
are removed. But if one of the operands is negative, the 4.0,
result is floored, i.e., rounded away from zero (towards -11//3 = -4,
negative infinity) − -11.0//3 = -
4.0

Simple Input and Output


Python provides numerous built-in functions that are readily available to us at the Python
prompt.
Some of the functions like input() and print() are widely used for standard input and output
operations respectively.

We use the input() function to input data to the standard input device .
We use the print() function to output data to the standard output device.
Python 2.7 offers two functions raw_input() but Python 3.7.1, Python 3.7.4 do not use
raw_input() function.

Interactive mode
Script Mode
Arithmetic Operators

Programming –
Open script mode [IDLE (Python 3.7 32-bit)] and click over the File -> New File option.
And write the following programs one by one. And save the file.
After that click Run -> Run Module or F5 function key for execute the program.

1. Program to obtain three numbers and print their sum


2. Program to obtain length and breadth of a rectangle and calculate its area.

3. Write a program to obtain temperature in Celsius and convert it into Fahrenheit using Formula.

4. Program to find maximum number among three numbers

You might also like