UNIT-1 Input_Output and Data_Types
UNIT-1 Input_Output and Data_Types
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• input() is used for standard input operations (to read data from
the user).
• input() function is used to read data from the standard input
device (keyboard) – during runtime.
Syntax:
Variable_name = input(“prompt”)
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
Example:
a = input(“enter a value = ”)
print(type(a))
a = int(a)
print(type(a))
a = float(a)
print(type(a))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
Example:
Output:
a = input(“enter a value = ”)
print(type(a))
a = int(a)
print(type(a))
a = float(a)
print(type(a))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Python takes all the input as a string input by default .
• To convert it to any other data type we have to convert the input
explicitly.
• int(), float() functions are used to convert this string into integer or
floating-point number.
Syntax:
Variable_name = data_type(input(“prompt”))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Reading int, float values during runtime.
Example1:
a = int(input(“enter a value = ”))
print(type(a))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Reading int, float values during runtime.
Example1: Output1:
a = int(input(“enter a value = ”))
print(type(a))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Reading int, float values during runtime.
Example1: Output1:
a = int(input(“enter a value = ”))
print(type(a))
Output2:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Reading int, float values during runtime.
Example1:
a = int(input(“enter a value = ”))
Print(a)
print(type(a))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Reading int, float values during runtime.
Example1: Output1:
a = int(input(“enter a value = ”))
Print(a)
print(type(a))
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Input:
• Reading int, float values during runtime.
Example1:
Output1:
a = int(input(“enter a value = ”))
Print(a)
print(type(a))
Output2:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Input and Output
Output:
• print() function is used to output data to the standard output
device (screen).
Syntax:
print(variable_name)
Example:
a = 5
print(a)
print(‘value of a is ’, a)
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Indentation in python
Most of the programming languages like C, C++, and Java use braces
{ } to define a block of code. Python, however, uses indentation.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Indentation in python
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Indentation in python
Example:
a=input("enter a")
b=input("enter b")
if a>b:
print('a is big')
print("hi")
else:
print("b is big")
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Numeric Datatypes:
• In Python, numeric data type represents the data that
has a numeric value.
• Numeric values can be integers, floating numbers, or
even complex numbers.
• These values are defined as
• int
• Float
• complex
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Numeric Datatypes:
• Integers – This value is represented by int class. It contains
positive or negative whole numbers (without fraction or decimal).
In Python, there is no limit to how long an integer value can be.
• Float – This value is represented by float class. It is a real number
with floating-point representation. It is specified by a decimal
point. Optionally, the character e or E followed by a positive or
negative integer may be appended to specify scientific notation.
• Complex Numbers – Complex number is represented by complex
class. It is specified as (real part) + (imaginary part)j. For example
– 2+3j
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Numeric Datatypes:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
• In Python, the sequence is the ordered collection of
similar or different data types.
• Sequences allow storing multiple values in an organized
and efficient fashion.
• There are several sequence types in Python.
• String
• List
• Tuple
• Range
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
• In Python, Strings are arrays of bytes representing Unicode
characters.
• A string is a collection of one or more characters put in a single
quote, double-quote, or triple quote.
• In python there is no character data type, a character is a string
of length one.
• It is represented by an str class.
• Strings in Python can be created using single quotes or double
quotes or even triple quotes.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
String:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
• Lists are just like the arrays, declared in other languages which is
an ordered collection of data.
• It is very flexible as the elements in a list do not need to be of the
same type.
• Lists in Python can be created by just placing the sequence inside
the square brackets [ ].
• It is represented by a list class.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Lists:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
• Just like a list, the tuple is also an ordered collection of Python
objects.
• The only difference between tuple and list is that tuples are
immutable i.e. tuples cannot be modified after being created.
• In Python, tuples are created by placing a sequence of values
separated by a ‘comma’ with or without the use of parentheses for
grouping of the data sequence.
• Tuples can contain any number of elements and of any datatype
(like strings, integers, lists, etc.).
• It is represented by a tuple class.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Sequence Datatypes:
Tuple:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Mapping Datatypes:
Dictionary:
• Dictionary in Python is an unordered collection of data values.
• Dictionaries are used to store data values in key: value pairs.
• In Python, a Dictionary can be created by placing a sequence of
elements within curly { } braces, separated by ‘comma’.
• Values in a dictionary can be of any data type and can be
duplicated, whereas keys can’t be repeated and must be
immutable.
• It is represented by a dict class.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Mapping Datatypes:
Dictionary:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Mapping Datatypes:
Dictionary:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Mapping Datatypes:
Dictionary:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Mapping Datatypes:
Dictionary:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Mapping Datatypes:
Dictionary:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Set Datatypes:
Sets:
• Python Set is the unordered collection of the data type.
• It is iterable, mutable (can modify after creation), and has unique
elements.
• In set, the order of the elements is undefined; it may return the
changed sequence of the element.
• The set is created by using a built-in function set(), or a sequence
of elements is passed in the curly braces and separated by the
comma. It can contain various types of values.
• It is represented by a set class.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Set Datatypes:
Sets:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Set Datatypes:
Sets:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Set Datatypes:
Sets:
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Boolean Datatype:
• Boolean type is one of the built-in data types provided by
Python, which are defined by the True or False keywords.
• Generally, it is used to represent the truth values of the
expressions.
• It is represented by a bool class.
>>> a = True
>>> type(a) Output:
<class 'bool'>
>>> b = False <class 'bool'>
>>> type(b)
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Boolean Datatype:
• In programming you often need to know if an expression is True
or False.
• You can evaluate any expression in Python, and get one of two
answers, True or False.
• When you compare two values, the expression is evaluated and
Python returns the Boolean answer
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Data types in Python
Boolean Datatype:
• The bool() function allows you to evaluate any value, and give you
True or False in return
• Almost any value is evaluated to True if it has some sort of content.
• Any string is True, except empty strings.
• Any number is True, except 0.
• Any list, tuple, set, and dictionary are True, except empty ones.
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Boolean Operations
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Boolean Logic
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE
Department
N BharathofKumar
Electrical and Electronics Engineering N BHARATH of
Department KUMAR
EEE