0% found this document useful (0 votes)
10 views

Introduction, Data Types, Data Scope,

Uploaded by

XYZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Introduction, Data Types, Data Scope,

Uploaded by

XYZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction, Data Types,

Data Scope, Input/output


Statements and Operators
Arithmetic, Relational, Logical and Bitwise Operators
Features of Python
• Simple :
• Simple Programming Language, when we read a Python program we feel like reading English
sentences.
• Easy to learn:
• Uses very few keywords
• Uses very simple structure
• Resembles to C programming language
• Most of the language constructs in C are also available in Python
• Open Source :
• There is no need to pay for the Python Software Freely downloadable
• High level language:
• Two types of languages : Low level ( uses machine code instructions to develop programs and directly
interact with the CPU. Machine language and assembly language are called low level languages)
• High level languages use English words to develop programs. These are easy to learn and use.
Features of Python
• Dynamically Typed :
• In Python, we need not declare anything.
• C, C++ and Java are statically typed – the variable names and datatypes should be
mentioned properly. Generates error if a wrong type is assigned to a variable name.
• In Python- if a name is assigned to an object of one type, it may later be assigned to an
object of a different type.
• Platform independent:
• Python compiler generates bytecode- with fixed set of instructions, that run on all the
operating systems and hardware
• Portable:
• When a program yields the same result on any computer in the world, then it is called a
portable program. Python programs will give the same result.
• Procedure and Object Oriented:
• Python is both procedure oriented and object oriented language
Comments in Python
• Single line comment – using #
# To find sum of two numbers

• Multi line comment- using triple double quotes (“””) or triple single
quotes (‘’’)
“”” This is a program to find net salary of an employee based on the
basic salary, provident fund, house rent allowance, dearness allowance
and income tax”””
How Python sees Variable
• In Python, a variable is seen as a tag (or name) tied to some value. For
example, the statement:
a=1
Means the value ‘1’ is created first in memory and then a tag by the name ‘a’ is
created.

Python considers the value (i.e. 1 or 2 etc..) as ‘objects’. If we change the value
of ‘a’ to new value as
a=2
Then the tag is simply changes to new value (or object). The value ‘1’now
becomes unreferenced object, it is removed by garbage collector.
Data types
Integer
• Integers are whole numbers. They have no fractional parts. Integers
can be positive or negative.
• There are two types of integers in Python:
• i) Integers(Signed) : It is the normal integer representation of whole numbers
using the digits 0 to 9. Python provides single int data type to store any
integer whether big or small. It is signed representation i.e. it can be positive
or negative.
• ii) Boolean : These represent the truth values True and False. It is a subtype of
integers and Boolean values True and False corresponds to values 1 and 0
respectively
Integer
• #Demonstration of Integer-Addition of two integer number
a=int(input("Enter the value of a:"))
b=int(input("Enter the value of b:"))
sum=a+b
print("The sum of two integers=",sum)

Output:
Enter the value of a: 45
Enter the value of b: 67
The sum of two integers= 112
Floating Point Numbers
• A number having fractional part is a floating point number.
• It has a decimal point.
• It is written in two forms :
• i) Fractional Form : Normal decimal notation e.g. 675.456
• ii) Exponent Notation: It has mantissa and exponent. e.g. 6.75456E2
Floating Point Numbers
• #Demonstration of Float Number- Calculate Simple Interest
princ=float(input("Enter the Principal Amount:")) rate=float(input("Enter the Rate of
interest:"))
time=float(input("Enter the Time period:"))
si=(princ*rate*time)/100
print("The Simple Interest=",si)

Output:
Enter the Principal Amount:5000
Enter the Rate of interest:8.5
Enter the Time period:5.5
Simple Interest= 2337.5
Complex Number
• Python represents complex numbers in the form a+bj.
#Demonstration of Complex Number- Sum of two Complex Numbers
a=7+8j
b=3.1+6j
c=a+b
print("Sum of two Complex Numbers")
print(a,"+",b,"=",c)
Output: (7+8j) + (3.1+6j) = (10.1+14j)
Strings
• A String is a group of valid characters enclosed in Single or Double
quotation marks.
• A string can group any type of known characters i.e. letters ,numbers
and special characters.
• A Python string is a sequence of characters and each character can be
accessed by its index either by forward indexing or by backward
indexing.
Strings
• #Demonstration of String- To input string & print it
my_name=input("What is your Name? :")
print("Greetings!!!")
print("Hello!",my_name)
print("How do you do?")
Output :
What is your Name? :Ananya Inkane
Greetings!!!
Hello! Ananya Inkane
How do you do?
Strings
• #Demonstration of String- To input string & print it
String1="Pankti"
print(String1) Output:
print(String1[0]) Pankti
P
print(String1[-1])
I
print(String1[1]) a
print(String1[-2]) t
Check type of the variable
• type() – built in function used to check the data type of the variable.
a=10
b=4.5
c="Hello"
d=7+8j

type(a)
int

type(b)
Float

type(c)
str

type(d)
complex
Arithmetic Operator
x=15
Relational Operator y=4
print("x>y is ",x>y)
print("x<y is ",x<y)
print("x==y is ",x==y)
print("x!=y is ",x!=y)
print("x>=y is ",x>=y)
print("x<=y is ",x<=y)

Output:
x>y is True
x<y is False
x==y is False
x!=y is True
x>=y is True
x<=y is False

v=x>y
print(v)
Output:
True
Print() – in built function to display
the data
a,b,c=2,3,4
str="Hello"
print(a)
print(a,b)
print(a,b,c)
print(a,b,c,str)
print(a,b,c,str + "Welcome!")
print(a,b,b,str + "\n Welcome!")
Input() – in built function to take
input from the user
• input() functions allow your Python Console application to read input from the user.
• Normally, the input() function reads the string from the console. Also, Python3
doesn’t distinguish whether the input is a string or a number. Whatever the user gives
as input through the console, it will receive as a String.
• Once we get string input by user in console, we can input as integer.
#read integer from user
n1 = int(input('Enter a number: '))
n2 = int(input('Enter another number: '))
print('The sum of two numbers is:', n1+n2)
ch=input("Enter a character:")
print(ch[0])

You might also like