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

Programming using Python

prutor.ai Amey Karkare


Dept. of CSE
IIT Kanpur

For any queries reach out to rahulgr@iitk.ac.in or rahulgarg@robustresults.com


or whatsapp 9910043510

1
Python Programming
Elements of Python
• A Python program is a sequence of
definitions and commands (statements)
• Commands manipulate objects

• Type: prutor.ai
• Each object is associated with a Type

– A set of values
– A set of operations on these values
• Expressions: An operation (combination of
objects and operators)

2
Programming
Types
• We have been using types
• In school mathematics
–Natural numbers

prutor.ai
• Values: 1, 2, 3, …
• Operations: +, - , *, >, <, …
–Complex numbers
• Values: 5 + 3i, 7 + 2i, …
• Operations: +, - , *, /, conjugate, …
• Operations >, < are NOT VALID
3
Programming
Types in Python
• int
– Bounded integers, e.g. 732 or -5

prutor.ai
• float
– Real numbers, e.g. 3.14 or 2.0
• long
– Long integers with unlimited precision
• str
– Strings, e.g. ‘hello’ or ‘C’

4
Programming
Types in Python
• Scalar
– Indivisible objects that do not have internal
structure

prutor.ai
– int (signed integers), float (floating point),
bool (Boolean), NoneType
• NoneType is a special type with a single value
• The value is called None
• Non-Scalar
– Objects having internal structure
– str (strings)
5
Programming
Finding Types of Expressions
You can use “type” function
to find the type of an expression

prutor.ai

6
Programming

You might also like