Lab 6
Lab 6
LAB # 6
DECLARAING VARIABLES AND DATA TYPES
OBJECTIVE
THEORY
Variable
A variable can have a short name (like x and y) or a more descriptive name
(age, carname,total_volume). Rules for Python variables:
Example
x= 5
y= "John"
print(x)
print (y)
Output:
>>> %Run task1.py
5
John
Variables do not need to be declared with any particular type and can even change type
after they have been set.
Example:
x= 4
x= "Sally"
print(x)
Output:
>>> %Run task2.py
Sally
Example:
Output:
>>> %Run task3.py
Orange
Banana
Cherry
Example:
x= "awesome"
print("Python is " , x)
Output:
>>> %Run task4.py
Python is awesome
Python Keywords
Keywords are the words whose meaning have already been explained to the Python
compiler. The keywords cannot be used as variable names, function name or any
identifier because if we do so we are trying to assign a new meaning to the keyword,
which is not allowed by the computer. Keywords are also called ‘Reserved words’. Some
keywords are as follows
Data Types
Data types specify how we enter data into our programs and what type of data we enter.
Python Data Types are used to define the type of a variable.
You can get the data type of any object by using the “type( )” function.
Operators
Operators are special symbols in Python that carry out arithmetic or logical
computation.
▪ Arithmetic operators
▪ Assignment operators
▪ Comparison operators
▪ Logical operators
▪ Identity operators
▪ Membership operators
▪ Bitwise operators
EXERCISE
x=5:
print(x)
B. Evaluate the operation in each of the following statements and show the
resultant value after each statement is executed.
b=3/2+5*4/3;
Lab Tasks: