Day2 Python
Day2 Python
DATA TYPES
Primarily these are the following data types in Python:
1. Integers
2. Floating point numbers
3. Strings
4. Booleans
5. None
Python is a fantastic language that automatically identifies the type of data for us.
Examples of a few variable names are: harry, one8, seven, _seven etc.
OPERATORS IN PYTHON
Following are some common operators in python:
10
TYPE() FUNCTION AND TYPECASTING.
type() function is used to find the data type of a given variable in python.
a = 31
type(a) # class <int>
b = "31"
type (b) # class <str>
A number can be converted into a string and vice versa (if possible)
There are many functions to convert one data type into another.
INPUT () FUNCTION
This function allows the user to take input from the keyboard as a string.
11
CHAPTER 2 – PRACTICE SET
1. Write a python program to add two numbers.
2. Write a python program to find remainder when a number is divided by z.
3. Check the type of variable assigned using input () function.
4. Use comparison operator to find out whether ‘a’ given variable a is greater than
‘b’ or not. Take a = 34 and b = 80
5. Write a python program to find an average of two numbers entered by the user.
6. Write a python program to calculate the square of a number entered by the user.
12