Grade 11
GETTING
STARTED
WITH
PYTHON
Presented by :
Rathish
INTRODUCTION
Python is a high-level, interpreted and general-purpose
dynamic programming language that focuses on code
readability.
The syntax in Python helps the programmers to do coding in
fewer steps as compared to Java or C++.
The language founded in the year 1991 by the developer Guido
Van Rossum has the programming easy and fun to do.
GUIDO VAN ROSSUM
Guido van Rossum is a Dutch
programmer best known as the author
of the Python programming language.
Python was developed in the year 1989
WHY PYTHON ?
When he began implementing Python,
Guido van Rossum was also reading the
published scripts from "Monty Python's
Flying Circus", a BBC comedy series from
the 1970s. Van Rossum thought he needed
a name that was short, unique, and slightly
mysterious, so he decided to call the
language Python.
PYTHON ADVANTAGES -
PLUS POINTS
01. Easy to Use.
02. Expressive Language.
03. Interpreted Language.
04. Its Completeness.
05. Cross Plat Form Language.
06. Free and Open Source.
07. Variety of Usage/Applications.
WORKING IN PYTHON
Python is free, open-source software that works on Linux, Mac,
Windows, and various other platforms (21 in total).
It comes preinstalled on Mac and most distributions of Linux.
There are multiple distributions available. python
Aside from the official CPython distribution available from
python.org, other distributions based on CPython include
the followings
PYTHON DISTRIBUTORS
WHAT IS AN IDLE?
An integrated development and learning environment
(IDLE) is a software application that provides
comprehensive facilities to computer programmers
for software development.
An IDE normally consists of a source code editor, build
automation tools, and a debugger. Most modern IDEs
have intelligent code completion.
PYTHON BASIC MODES
Python has two basic modes:
1) Script
The normal mode is the mode where the scripted and
finished .py files are run in the Python interpreter.
Programs written in script mode are reusable.
2) Interactive.
Interactive mode is a command line shell which gives
immediate feedback for each statement, while running
previously fed statements in active memory.
PYTHON
FUNDAMENTALS
Also known
as
Lexical Unit
WHAT IS KEYWORD?
Keywords are also called as reserved words these are
having special meaning in python language. The words
are defined in the python interpreter hence these cant be
used as programming identifiers.
VARIABLE
In Python, a
variable is a
named storage
location that
holds data
IDENTIFIERS
Identifiers Python is a names given to a variable, function, class,
module, or other objects in order to identify them
Rules for Naming Python Identifiers
Keyword cannot be used as an identifier.
It should not contain white space, blank spaces.
It can be a combination of A-Z, a-z, 0-9, or underscore.
It cannot start with digits.
It should not contain any special character other than an
underscore ( _ ).
Python is case sensitive
Find the valid and invalid identifiers
LITERALS
Literals are also called as constants or constant values these are
the values which never change during the execution of program.
Types of literals
1) String Literals or Constants.
2) Numeric Literals or Constants.
3) Boolean Literals or Constants.
4) Special Literal None.
5) Literal Collections.
STRING
Sequence of letters enclosed in quotes is called string or string
literal or constant.
Python supports both form of quotes i.e.
'Hello'
"Hello"
TYPES OF STRING LITERAL
SINGLE LINE STRINGS
Strings created using single quote or double quote must end in
one line are called single line strings
For Example:
Item="Computer"
Or
Item= 'Computer'
MULTI LINE STRINGS
Strings created using single quote or double quote and spread
across multiple lines are called Multi Line Strings.
by adding backslash \ one can continue to type on next line.
Or by specifying within triple Quotes
For instance:
Item = 'Key\ board' OR Item = ‘ ‘ ‘ Key
board ‘ ‘ ‘
MULTI LINE STRINGS
Strings created using single quote or double quote and spread
across multiple lines are called Multi Line Strings.
by adding backslash \ one can continue to type on next line.
Or by specifying within triple Quotes
For instance:
Item = 'Key\ board' OR Item = ‘ ‘ ‘ Key
board ‘ ‘ ‘
BOOLEAN LITERAL:
TRUE (1) FALSE (0)
bool() -empty
bool(0)
bool(‘’) - returns false
rest everything it return True
SPECIAL LITERAL
'None' is used to define a null variable.
ie Absence of value to the variable.
If 'None' is compared with anything else
other than a 'None', it will return false.
A variable will be created only when
some value is assigned to it.
Using None an empty variable can be
created ie in absence of value
NUMERIC LITERALS
Integer Literals – Whole numbers (positive, negative, or
zero) without a decimal point. Example: 10, -25, 0
Floating-point (Decimal) Literals – Numbers with a
decimal point, representing real numbers. Example:
3.14, -0.01, 2.0
Complex Number Literals – Numbers in the form a + bj,
where a is the real part and b is the imaginary part.
j-- -1 indicates Example: 5 + 2j, 7 - 3j
OPERATORS
Python operators are special symbols used to perform
specific operations on one or more operands. The
variables, values, or expressions can be used as operands
Eg: c = a + b
here
c, a, b are operands
=+ are operators
TYPES OF OPERATORS
Unary operators: Python operators that require one
operand to perform a specific operation are known as
unary operators.
Binary operators: Python operators that require two
operands to perform a specific operation are known
as binary operators.
TYPES OF OPERATORS
Arithmetic Operators
Comparison (Relational) Operators
Assignment Operators
Logical Operators
Bitwise Operators
Membership Operators
Identity Operators
ARITHMETIC
COMPARISION / RELATIONAL
ASSIGNMENT
LOGICAL
MEMBERSHIP
IDENTITY
PUNCTUATORS
BAREBONES OF PYTHON
Expression: which is any legal combination of symbols that
represents a value
Statement: which are programming instructions
Comments: which is the additional readable information to
clarify the source code can be either Single line Comment (#)
or Multiline comments triple-quoted strings
Functions: which are named code section and can be reused
by specifying their names function calls.
Block or suits: which is a group of statement which is part of
another statement or function. All statement inside a block or
suite is indented at the same level.
Solve the Following Expression and predict the Output
1.51 + 4 - 3 **3//19-3
2. print(6 *3/4**2//5-8)
3.3 ** 2**3
4. 6 <12 and not(20>15) or (10 > 5)
5. (15.0 // 4 + (8 + 3.0))
6. 10 > 5 and 7 > 12 or not 18 >3
7. not(10 == 10)
8. True or not True and False
9. not True and False or not True
10. not False and False or True
Variables
Variable represent labeled storage locations, where values can
be manipulated during program run.
Variable Creation
It will be created only when we assign values to the
variable
Variable declaration is implicit / internal in python
Assigning values to the Variables
age = 20
Here age is a variable that holds the data 20 of type
integer (whole number)
In other programming languages we externally declare
the variable. Eg in c++
int age;
age = 20
Dynamic Typing.
A variable pointing to a value of certain type can be
made to point to a value/object of different type. This is
called dynamic Typing.
x=10
print(x)
x='hello world'
print(x)
Multiple assignments
Assuming same value to multiple variables. You can
assign same value to multiple variable in a single
statement e.g.,
a = b = c =100
Assuming different values for different variables in a
single line
a, b, c = 10, 20, 30
m, n, o = 20.5, 30, “alpha”
First value at the right side will be assigned to the first
variable at the left side and so on
I / O Statements - Input Statement
We use input() function to take the value from the
user.
Syntax:
Variable_name = input(Message)
Example:
Mobile = input(“Enter your mobile number”)
Message given to the user
The given input to notify what input / data
data will be stored to be entered
here
I / O Statements - Input Statement
When the interpreter encounters input() function, it
waits for the user to enter data from the standard
input stream (keyboard) till the Enter key is pressed
The default data type of input function is string
In the previous example the value entered by the user
will be considered as string (ie. alphabets)
You can also specify the specific data type to get the
input from the user in combination with input() they are
int(), float(), etc according to your requirement in user’s
input()
I / O Statements - Input Statement
name = input(“Enter your name”)
age = int(input(“Enter your age ”))
salary = float (input(“Enter your salary”))
Converts
Converts the
the data
data into float
into int type
type
I / O Statements - OUTPUT Statement
Python's print() function is a built-in function. It is the
most frequently used function, that displays value of
Python expression given in parenthesis
print(“My world”)
dessert = “Brownie”
qty = 10
print(“Get me the dessert ” , dessert , “of quantity =”, qty)
I / O Statements - OUTPUT Statement
Sep keyword - used to specify the separator between the
strings / Values
a= 20
b = 30
print(a, b , sep=”$”)
print(a, sep=”$”)
I / O Statements - OUTPUT Statement
The end keyword in Python is primarily used as a
parameter within the print() function. It specifies what
character or string should be appended at the end of the
printed output, instead of the default newline character
(\n).
a= 20
b = 30
print(a, end=” “)
print(b)
print(a + b, end =”@”)
Points to remember
THANK YOU Tokens - Keywords, Identifier
SO MUCH Punctuators, Operators,
Literals & types
Operator Precedence &
Barebones of Python
I / O statements