2. Getting Started with Python second lesson .pptx
1. Introduction of Python
What is Python?
Python is general Purpose High Level Programing Language
It can be used For
1. Desktop Application
2. Web Application
3. Mobile Application
3. About Python
• It has very simple and straight forward Syntax.
• Python is case sensitive Language.
• It is an Object Oriented Programing Language.
• Dynamically Typed .
• Executed by interpreter
• Can run in various operating systems. Indentation is used in place of Curly Braces.
• Use variable without declaration.
• It is an Interpreted Language.
4. Features
• Emphasis on Code readability.
• Automatic Memory Management.
• Dynamically Typed
• Large Library
• Platform Independent
5. Features
• Easy to use – Due to simple syntax rule
• Interpreted language – Code execution & interpretation line by line
• Cross-platform language – It can run on windows, Linux, Macintosh
etc. equally
• Expressive language – Less code to be written as it itself express the
purpose of the code.
• Completeness – Support wide rage of library
• Free & Open Source – Can be downloaded freely and source code can
be modify for improvement
6. Working with python
• To run a python pgm, install a python interpreter at first
• Interpreter is also called as python shell
• >>>shows python prompt is ready to take instructions
• We can type in this prompt to execute them using python
interpreter
7. Two ways of python interpreter
• Interactive mode
• Script mode
8. Interactive mode
• Simply type in >>> prompt.
• Immediately executed of individual statement
• Convini ent for testing single line code for instant execution
• We cannot save the statements for future use
• Retype and run again
• Eg:
• 1+2
• Answer we get immediately
9. Script mode
• In a file, we type, save then execute it
• Extension is .py
• Tell the students to write a program to show print statements
in script mode
10. Python keywords
• Reserved words
• Each word has a specific meaning
• we use keyword only for the purpose for which it has been
defined
• Python is Case sensitive , so exactly we have to write
11. • We cannot use a keyword as a variable name, function name or any
other identifier. They are used to define the syntax and structure of the
Python language.
• In Python, keywords are case sensitive.
• There are 33 keywords in Python 3.7. This number can vary slightly
over the course of time.
• All the keywords except True, False and None are in lowercase and
they must be written as they are..
13. identifiers
• Used to identify a variable, function or entity in program
• Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or
digits (0 to 9) or an underscore _ . ...
• An identifier cannot start with a digit. ...
• Keywords cannot be used as identifiers. ...
• We cannot use special symbols like !, @, #, $, % etc. ...
• An identifier can be of any length.
• Ex: marks 1, mark2, avg like that words used to identify by us for write a program
• Area=length*breadth
14. variables
•A variable is a label that you can assign a value to it. The
value of a variable can change throughout the program.
•A=‘m’
•Message=“keep smiling”
•Price=587.6
15. comments
• Remark or note in the source code
• Easier for other persons also to understand
• #sign starts till end of # considered as comment
• Simply ignores while executing the statement
16. Data types
Variables can store data of different types, and different types can do
different things.
Python has the following data types built-in by default, in these
categories:
18. Numbers or numeric
Type description
example
Int integer numbers
-12,-3,0,125
Float real or floating numbers -2.04, 4.0,
14.23
Complex complex numbers 3+4i,
2-2i
19. Boolean (bool)
• It is a subtype of integer
• It is a unique data type
• Consists of two constants (True and False)
• Boolean True value is non-zero, non null, non empty
• Boolean False is value zero
21. string
•– group of characters
•->>>str1=‘hello’
•->>>str2=“452”
•We cannot perform numerical operations on
strings, even when the string contains a value as
in str2
22. list
Sequence of items separated by commas and the items enclosed in
square brackets[]
Ex:
>>>list1=[10,3.5,”new delhi”,’welcome’,50]
>>>print(list1)
23. tuple
• Sequence of items separated by commas and the items enclosed
in parenthesis()
• Ex
• Tuple1=(10,20,”apple”,3.4,’a’)
• Print(tuple1)
24. SET
• Unordered collection of items
• {}
• No duplicate entries
• Ex
• Set1={10,20,10,’apple’}
• Print(type(set1))
• <class’set’>
• Print(set1)
• Output{10,20,’apple’}
25. NONE
• Special data type with a single value
• Used to signify the absence of value in a situation
• None supports no special operations, and it is neither false nor
zero
26. mapping
• Unordered datatype
• One standard mapping datatype is called dictionary
• Holds data items in key value pairs
• {}
• Dictionaries permit faster access to data
• Every key is separated from its value using a colon: sign
• >>>dict1={‘fruit’:’apple’,’climate’:’cold’}
• Print(dict1)
27. Mutable and immutable data types
• List and dictionary are mutable datatypes
• Refer page no 98 in NCERT BOOK
• MEMORY ALLOCATION OF num1, num2, num1=num1+100
28. Deciding usage of python data types
• For storing names of students, easy to update when new
admission join
• Tuples use when no change ex- names of months in a year
• When need uniqueness , avoid duplicacy, we use sets
• When we need logical association between the key:value pair,
advising to use dictionaries
• Ex: mobile phone book is a good application of dictionary
29. operators
• To perform mathematical or logical operation on values
• Values that the operators work on are called operands
• Ex: 10+num,
• Value is 10
• Variable num operands and the + sign is an operator
31. expression
• Combination of constants, variables and operators
• Always evaluates a value
• A value or variable is also considered as an expression but a
standalone operator is not an expression
• Precedence Of expression refer pg 105 in NCERT
32. STATEMENT
• IN PYTHON, A STATEMENT IS A UNIT OF CODE THAT THE PYTHON
INTERPRETER CAN EXECUTE PG NO 106 IN NCERT BOOK
33. INPUT, OUTPUT
• It accepts all user input as string
• Input([prompt])
• Input function terminated by pressing enter key