際際滷

際際滷Share a Scribd company logo
PYTHON
FUNDAMENTALS
Previous Knowledge
Testing
1. Who developed Python?
Guido Van Rossum
2. Name the Pythons two working mode.
Interactive & Script
3. Python programs are stored in files with _________
extension.
.py extension
4. Python is the fastest language. True / false
False
5. Which statement is used to display
output on the screen?
Print statement
Syntax:
print( <objects to be printed in quotes>)
For example:
print( Computer Science )
Output :
Computer Science
Print statement
Arguments inside print statement:
sep & end
Sep  is used to separate word
eg. x,y=10,20
print(x , y)
Output :
10 20
Print statement
Arguments inside print statement:
sep & end
end  is used to separate word
eg. x,y=10,20
print(x)
print(y)
Output :
10 20
print(x, end =  )
INTRODUCTION
TO
PYTHON FUNDAMENTALS
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++.
Let us learn the basic elements of python
programming
What is Character Set?
PYTHON CHARACTER SET
What is Character Set?
Character set is
identifying elements
a bunch of
in the
programming language.
PYTHON CHARACTERSET
PYTHON CHARACTER SET
PYTHON
CHARACTER
SET
 Letters:- A-Z, a-z
 Digits:- 0 to 9
 Special Symbols:- space + - / ( ) [ ] = ! = < > ,   $ # ; : ? &
 White Spaces:- Blank Space , Horizontal Tab, Vertical tab,
Carriage Return.
 Other Characters:- Python can process all 256 ASCII and
Unicode Characters.
11-unit1chapter02pythonfundamentals-180823043011.pptx
What is Token or lexical unit?
TOKENS OR LEXICAL UNIT
What is Token?
Individual elements that are
identified by programming language are
called tokens or lexical unit.
TYPES OF LEXICAL UNITS
TOKENS / LEXICAL UNITS
TOKENS
1. Key
Word
s
2.
Identifiers
3. Literals
4.
Operators.
5.
Punctuators
What is Keyword or reserved word?
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.
1. Keyword/Reserved Word
Some Keywords of Python Language
Some Keywords of Python Language
and assert
break
continue
del
else
exe
c
class
def
elif
excep
t
finally
from
Some Keywords of Python Language
global
if
import in
is lambda not
or
pass print
raise
return try while
with yield
What is an identifier?
2. IDENTIFIERS
What is an identifier?
A Python Identifier is a name given
to a function, class, variable, module, or
other objects that youll be using in
your Python program.
In short, its a name appeared in the
program.
For example: a, b, c
a b and c are the identifiers
and a b & c and , are the
PYTHON NAMING CONVENTIONS
OR
IDENTIFIER FORMATION RULES
PYTHON NAMING CONVENTIONS
the python
naming
What are
conventions?
1. An identifier can be a combination
of uppercase letters, lowercase letters,
underscores, and digits (0-9). Hence,
the following are valid identifiers:
myClass, my_variable, var_1, and
print_hello_world.
PYTHON NAMING CONVENTIONS
What are the python
naming conventions?
2. The first character must be letter.
3. Special characters such as %,
@, and
$ are not allowed within identifiers.
4. An identifier should not begin
with a
number. Hence, 2variable is
not valid, but variable2 is acceptable.
the python
naming
What are
conventions?
5. Python is a case-sensitive
language and this behaviour extends to
identifiers. Thus, Labour and labour are
two distinct identifiers in Python.
6. You cannot use Python keywords
as identifiers.
PYTHON NAMING CONVENTIONS
the python
naming
What are
conventions?
7. You cannot use Python keywords as
identifiers.
8. You can use underscores to separate
multiple words in your identifier.
PYTHON NAMING CONVENTIONS
SOME VALID IDENTIFIERS:
Myfile1
y3m9d3
MYFILE
DATE9_7_8
_xs
_FXd
SOME INVALID IDENTIFIERS:
MY-REC 28dre break
elif false del
PYTHON NAMING CONVENTIONS
Competency Based
Question
1. Write Instructions in python to get the following
result: (Do it in both interactive mode and script
mode)
 I am a student of KV Barabanki
 I live in Barabanki
 And I love Barabanki.
 Barabanki is 20 KM away from Lucknow
 This Place is famous for Dewa Sharif
HOME WORK
1. What are tokens in python? How many
tokens are allowed in Python?
2. How keyword are different from
identifiers?
3. Application based Question:
a,b,c = 2,8,9
print(a,b,c)
print(b,c,a)
What is literals?
3. LITERALS / CONSTANT VALUES
What is literals?
Literals are also called as constants
or constant values these are the values
which never change during the
execution of program.
What are the types of
literals?
TYPES OF LITERALS / CONSTANT VALUES
What are the 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.
What is string?
1. STRING LITERALS OR CONSTANTS
What is string?
Sequence of letters enclosed in
quotes is called string or string literal or
constant.
both form of
Pythonsupports
quotes i.e.
Hel
lo
Hello
Representation of String
REPRESENTATION OF STRING
Forward Indexing
>>> s = Hello Python
This is how Python would index the string:
Backward Indexing
REPRESENTATION OF STRING
To access the first character on the string
you just created, type and enter the variable
name s and the index 0 within square brackets
like this:
>>>s[0]
Youll get this
output: H
REPRESENTATION OF STRING
To access the last character, you can use this
expression:
>>>s[len(s)-1]
Youll get the output:
n
Len() function
is used to
find the
length of the
string.
REPRESENTATION OF STRING
The expression introduces you to the
len function. There is actually an easier way to
access the last item on the string:
>>>s[-1]
n
To access the penultimate character:
>>>s[-2]
o
TYPES OF STRINGS
What are the types of strings supported
in python?
Python supports two ways
of representation of strings:
1) Single Line Strings.
2) Multi Line Strings.
TYPES OF STRINGS
SINGLE LINE STRINGS
Strings created using single quote or
double quote must end in one line are
called single line strings
For Example:
Item=Compu
ter 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.
For instance: Item = Key
board
SIZE OF STRINGS
SIZE OF STRINGS

abc
ab
Raamas Laptop
Size is 1 ( is an
escape sequence)
size is 3
size is 2
size is 13
Strings with Triple Quotes
STRINGS WITH TRIPLE QUOTES
For multi line strings created by triple
quotes, while calculating size, the
EOL(End of Line) character at the end of
line is also counted.
For instance:
Str2=x
y
Z
Enter keys are
considered
as EOL so size
of str2 is 5
Escape Sequences
ESCAPE SEQUENCES
Back Slash
Single Quote ()


 Double Quote ()
ESCAPE SEQUENCES
ASCII Bell
ASCII Backspace
ASCII Formfeed
a
b
f
ESCAPE SEQUENCES
New Line
Carriage return
Horizontal Tab
n
r
t
ESCAPE SEQUENCES
Vertical Tab
16 bit hex
value
Octal Value
t
x
ooo
Back Slash
Single Quote
Double Quote
ASCII Bell
a
ASCII Backspace
b
ASCII Form Feed
f
New Line
n
Carriage Return
r
Horizontal Tab
t
Vertical Tab
v
16 bit Hex Val
x
Octal Value
ooo
Note: ooo represents 3 octal digits.
2. NUMERICAL LITERALS
Numerical Literals have the
following types:
int or integers
float
Complex
- Whole numbers
- real values
- Complex numbers
2. NUMERICAL LITERALS
Numerical Literals have the
following types:
int or integers
float
Complex
- Whole numbers
- real values
- Complex numbers
INTEGER LITERALS OR CONSTANTS
 Decimal Integer Literals: Any whole
number (+ve) or (-ve).
INTEGER LITERALS OR CONSTANTS
Octal Integer Literals(base 8): A Sequence of
digits starting with 0O (digit zero followed by
letter o) is taken to be an Octal Integer
Literals.
INTEGER LITERALS OR CONSTANTS
Hexadecimal Integer Literals (base 16):
Sequence of digits preceded by ox or OX is
hexadecimal integer literals
INTEGER LITERALS OR CONSTANTS
Binary literals (base 2): To signify binary
literals, youll use the prefix 0B or 0b (zero
and uppercase or lowercase b).
Converting Integers to their String
Representation
To convert an integer into its
string
representation, you can use the functions hex(),
bin(), and oct().
To convert the integer 7 to its octal literal, type
and enter oct(7) on the command prompt. Youll
get the output 0o7:
oct ( )
Here is what happens when you convert
the integer 2572 to a hexadecimal literal:
hex ( )
see what happens when you use the bin()
function to convert the integer 12 to its binary
string:
bin ( )
FLOATING POINT LITERALS OR CONSTANTS
FLOATING POINT LITERALS OR CONSTANTS
Floating point literals are
also called as real literals having fractional
part.
These may be written in one of the
two forms:
1. Fractional Form: for example 15.75
2. Exponent Form: It consists of two parts
Mantissa and Exponent. for example 5.8 can
be represented as 0.58 x 10-1 = 0.58E01.
FLOATING POINT LITERALS OR CONSTANTS
Float type
BOOLEAN LITERALS OR CONSTANTS.
3) BOOLEAN LITERALS OR CONSTANTS.
A Boolean literal in python is used
to represent the Boolean values (true or
false).
Special Literal - None
4) SPECIAL LITERAL NONE
The None literal is used to indicate
absence of value.
For example: val = None
LITERAL COLLECTIONS
5) LITERAL COLLECTIONS
Python supports literal
collections also such as tuple and lists ..etc
It will be to complex to discuss as we are
in the beginning, subsequent chapters we will
cover literal collections.
OPERATORS
OPERATORS
What is an operator?
Operators are tokens
that
trigger some
computation when applied to a variable.
that
What is Unary Operator?
Unary operators are those
operators require one operand to
operate upon.
Unary Operators:
+
-
~
not
Unary Plus
Unary Minus
Bitwise Compliment
Logical Negation
OPERATORS
What is Binary Operator?
Binary operators are those operators
that require two operands to
operate upon.
Binary Operators:
+
-
*
/
%
**
//
Addition
Subtraction
Multiplication
Division
Remainder or Modulus
Exponent.
Floor Division
OPERATORS
What is Binary Operator?
Binary operators are those operators
that require two operands to
operate upon.
Binary Operators:
+
-
*
/
%
**
//
Addition
Subtraction
Multiplication
Division
Remainder or Modulus
Exponent.
Floor Division
OPERATORS
Bitwise Operators:
&
^
|
Bitwise AND
Bitwise Exclusive OR
Bitwise OR
Shift Operators:
<<
>>
Shift Left
Shift Right
OPERATORS
Relational Operators:
<
>
<=
>=
==
!=
Less than
Greater than
Less than equal to
Greater than equal to
Equal to
Not equal to
Logical Operators:
and
or
Logical AND
Logical OR
BINARY OPERATORS EXAMPLE
BINARY OPERATORS EXAMPLE
BINARY OPERATORS EXAMPLE
Exponent
Floor
Division
BITWISE OPERATORS EXAMPLE
BITWISE AND & EXAMPLE
BITWISE
AND
OPERATO
R
BITWISE AND & OPERATOR EXAMPLE
& operator picks bits exists in both
the operands (common)
BITWISE OR | EXAMPLE
BITWISE OR
| OPERATOR
BITWISE OR | OPERATOR
EXAMPLE
| operator picks bits exists in either
the operands ( any one or both )
BITWISE OR EXCLUSIVE ^ EXAMPLE
BITWISE EXCLUSIVE OR ^ OPERATOR EXAMPLE
BITWISE ^
OPERATOR
It picks up bit if it is one operand not in both
(uncommon)
SHIFT OPERATORS EXAMPLE
BITWISE ONEs COMPLIMENT
~ OPERATOR EXAMPLE
BINARY ONEs COMPLIMENT ~ OPERATOR
EXAMPLE
It is the unary operator which has a flipping
effect.
<< BINARY LEFT SHIFT
OPERATOR EXAMPLE
BINARY << LEFT SHIFT EXAMPLE
The first operands value is moved left by the
number of bits specified by the second operand.
<< BINARY RIGHT SHIFT
OPERATOR EXAMPLE
BINARY >> RIGHT SHIFT EXAMPLE
The first operands value is moved right by the
number of bits specified by the second operand.
Assignment Operators
OPERATORS
Assignment Operators:
=
*=
/=
+=
-=
%=
**=
//=
Assignment Operator
Assign Product
Assign Quotient
Assign Sum
Assign Minus
Assign Remainder
Assign Exponent
Assign Floor Division.
DIFFERENT ASSIGNMENT
STATEMENT EXAMPLE
BINARY >> RIGHT SHIFT EXAMPLE
OPERATORS
Membership Operators:
in weather variable in sequence.
not in weather variable not in sequence
MEMBERSHIP
OPERATOR
EXAMPLE
MEMBERSHIP OPERATOR EXAMPLE
PUNCTUATORS
Punctuators are also called as separators
The Followings are used as punctuators:
Brackets [ ]
Parentheses ( )
Braces { }
Comma ,
Semicolon ;
Colon :
Asterisk *
Ellipsis 
=
Equal Sign
Pound Sign
#
GENERAL STRUCTURE
OF
PYTHON PROGRAM
GENERAL STRUCTURE OF PYTHON PROGRAM
#Comments
GENERAL STRUCTURE OF PYTHON PROGRAM
GENERAL STRUCTURE OF PYTHON PROGRAM
# Write a program to find
square of given number.
def sqr( num ):
result= num *num
print ("Square = " ,
result)
def main():
x=int(input("Enter the number : "))
sqr(x)
main()
Programmer
defined
FUNCTION
main() function
Comment
WHITE SPACE
Whitespace Whitespace is meaningful
in Python, especially indentation and
placement of newlines.
 Use a newline to end a line of code.
 Use  when must go to next line
prematurely.
 No braces { } to mark blocks of code in
Python
WHITE SPACE
WHITE SPACE
 Use consistent indentation instead.
 The first line with less indentation is
outside of the block.
 The first line with more indentation
starts a nested block.
 Often a colon appears at the start of a
new block. (E.g. for function and class
definitions.).
COMMENTS
COMMENTS
Comments are non executable
statements in a program.
Single line comment always starts
with #
Multiline comment will be in triple
quotes. For example  write a program
to find the simple interest .
Note: Triple apostrophe is called
docstrings.
STATEMENTS
STATEMENTS
In computer terminology statement
refers to an instruction.
Program contains several
statements. A collection of statements
makes program
Another name for a program is
code.
FUNCTIONS
FUNCTIONS
What is function?
Function is a self contained program
segment which carries out some specific
well defined task.
For Example:
def sqr( num ):
result= num *num
print ("Square = " , result)
sqr()
PYTHON PROGRAMMING CONVENTIONS
PYTHON PROGRAMMING CONVENTIONS
Statement Termination: python does
not use any symbol to terminate the
statement.
Maximum Line Length: Line Length be
maximum 79 characters.
Whitespaces: you should always have
whitespace around operators but not
with parenthesis.
PYTHON PROGRAMMING CONVENTIONS
Block or Code Block: A group of
statements which are part of another
statement or function is called Block or
Code Block.
Case Sensitive: Python is case sensitive.
VARIABLES AND ASSIGNMENTS
VARIABLES AND ASSIGNMENTS
Named labels are called variables.
For example: marks =86
78 79 80 81 82 83 84 85 86 87
2000 2016 2018 2026 2032 2044 2048 2050 2054 2068
marks refers to
location 2054
VARIABLES AND ASSIGNMENTS
Now marks = 81
78 79 80 81 82 83 84 85 86 87
2000 2016 2018 2026 2032 2044 2048 2050 2054 2068
marks
refers to
location
2026
VARIABLES AND ASSIGNMENTS
lvalues & rvalues:
Lvalue:Expressions that is on
LHS (Left Hand Side) is called Lvalue.
Rvalue: Expressions that is on RHS (Right
Hand Side) is called Rvalue.
VARIABLES AND ASSIGNMENTS
Multiple Assignments
Python is very versatile
with assignment statements.
to multiple
1. Assigning same
value variables:
a=b=c=d=e=10
VARIABLES AND ASSIGNMENTS
Multiple Assignments
2. Assigning Multiple values to multiple
variables:
p,q,r =5,10,15
print(q, r) will print 10
15
p,q=q,p
print (p,q) will print 10 5
VARIABLES AND ASSIGNMENTS
Multiple Assignments
2. Assigning Multiple values to multiple
variables:
a,b,c = 5,10,7
b,c,a = a+1, b+2, c-1
print(a,b,c) will print 6 6 12
Now,
X=10
VARIABLES AND ASSIGNMENTS
Multiple Assignments
Expressions separated by
commas are evaluated from left to
right.
Now,
x = 10
y,y = x+2,x+5
y,y = 12,15
First It will assign y = 12 then y = 15
So print(y) will print 15
VARIABLES AND ASSIGNMENTS
Dynamic Typing:
A variable pointing to a
value of certain type can be made to
point to a value/object
this is called Dynamic
of different
type Typing.
x=10
print(x)
x= Hello World
print(x)
VARIABLES AND ASSIGNMENTS
Output will be
10
Hello World
10
10
Hello World
x
x
VARIABLES AND ASSIGNMENTS
Caution with Dynamic Typing:
x = day
y = x/2 Error! String can not be divided.
VARIABLES AND ASSIGNMENTS
type() function:
To know the data type of a value which is
pointing use type ( )
>>>a=10
>>>type(a)
<class int>
>>>a=20.4
>>>type(a)
<class float>
Type returned as integer
Type returned as float
VARIABLES AND ASSIGNMENTS
type() function:
To know the data type of a value which is
pointing use type ( )
>>>a=Hello
>>>type(a)
<class str> Type returned as string
INPUT ( ) FUNCTION
INPUT ( ) FUNCTION
Input( ) Function is a built in function
of python used to read values from the user
The general format or syntax of the input() is:
Variable_to_hold_the_value=input(mess
age) For Example:
Where,
variable
location
variable_to_Hold_the_Value is a
which is the label for a memory
where the value is stored.
INPUT ( ) FUNCTION
For Example:
p = input(Enter the value)
x = int(input(Enter x value))
reads the value and converts it in to integer
type data or value.
y=float(input(Enter y value))
reads the value and converts it in to float type
data or value.
INPUT ( ) FUNCTION
int ( ) and float ( ) Functions:
Python offerstwo functions to be
used with input( ) to convert the
received values:
Example 1: >>age =
int(input(Enter age)) Example 2:
>>sal=float(input(Enter salary))
PRINT ( ) FUNCTION
PRINT ( ) FUNCTION
print( ) Function is a built in function of
python used to display the values on the
screen
The general format or syntax of the input() is:
print(*objects, sep=' ', end='n',
file=sys.stdout,
flush=False)
The print function can print an arbitrary
number of values ("value1, value2, ..."), which are
separated by commas. These values are separated
by blanks. In the following example we can see
two print calls. We are printing two values in both
cases, i.e. a string and a float number:
PRINT ( ) FUNCTION
print() Parameters:
objects - object to the printed. * indicates that
there may be more than one object
sep - objects are separated by sep. Default
value: '  end - end is printed at last
file - must be an object with write(string)
method. If omitted it, sys.stdout will be used
which prints objects on the screen.
flush - If True, the stream is forcibly
flushed. Default value: False
PRINT ( ) FUNCTION
Example 1: How print() works in Python?
print("Python is fun.")
a = 5
#Two objects are passed: print("a
=", a)
b = a
# Three objects are passed:
print('a =', a, '= b)
Output
Python is fun.
a = 5
a = 5 = b
PRINT ( ) FUNCTION
Example 2: How print() works in Python?
>>> print("a = ", a)
a = 3.564
>>> print("a = n", a)
a =
3.564
>>>
Any Questions Please
Thank You

More Related Content

Similar to 11-unit1chapter02pythonfundamentals-180823043011.pptx (20)

An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
Ravikiran708913
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
UNIT 1 PY .ppt - PYTHON PROGRAMMING BASICS
UNIT 1 PY .ppt -  PYTHON PROGRAMMING BASICSUNIT 1 PY .ppt -  PYTHON PROGRAMMING BASICS
UNIT 1 PY .ppt - PYTHON PROGRAMMING BASICS
drkangurajuphd
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
Pyhton problem solving introduction and examples
Pyhton problem solving introduction and examplesPyhton problem solving introduction and examples
Pyhton problem solving introduction and examples
ssuser65733f
Chapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptxChapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptx
atharvdeshpande20
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
ZENUS INFOTECH INDIA PVT. LTD.
Python
PythonPython
Python
Gagandeep Nanda
python-ch2.pptx
python-ch2.pptxpython-ch2.pptx
python-ch2.pptx
SameerAlbadani
Python Programming Introduction demo.ppt
Python Programming Introduction demo.pptPython Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
alaparthi
python and perl
python and perlpython and perl
python and perl
Mara Angelica Refraccion
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
samiwaris2
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek Purushothaman
PYTHON.pdf
PYTHON.pdfPYTHON.pdf
PYTHON.pdf
LovelyLabordoParacha
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
Python knowledge ,......................
Python knowledge ,......................Python knowledge ,......................
Python knowledge ,......................
sabith777a
CH6 - Fundamentals of Python.pptx
CH6 - Fundamentals of Python.pptxCH6 - Fundamentals of Python.pptx
CH6 - Fundamentals of Python.pptx
EloAOgardo
Biswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptxBiswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptx
BiswambarBehera5
Python Guide.pptx
Python Guide.pptxPython Guide.pptx
Python Guide.pptx
NoumanShamim50145TCH
An overview on python commands for solving the problems
An overview on python commands for solving the problemsAn overview on python commands for solving the problems
An overview on python commands for solving the problems
Ravikiran708913
python ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institutepython ppt | Python Course In Ghaziabad | Scode Network Institute
python ppt | Python Course In Ghaziabad | Scode Network Institute
Scode Network Institute
UNIT 1 PY .ppt - PYTHON PROGRAMMING BASICS
UNIT 1 PY .ppt -  PYTHON PROGRAMMING BASICSUNIT 1 PY .ppt -  PYTHON PROGRAMMING BASICS
UNIT 1 PY .ppt - PYTHON PROGRAMMING BASICS
drkangurajuphd
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
Pyhton problem solving introduction and examples
Pyhton problem solving introduction and examplesPyhton problem solving introduction and examples
Pyhton problem solving introduction and examples
ssuser65733f
Chapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptxChapter 1-Introduction and syntax of python programming.pptx
Chapter 1-Introduction and syntax of python programming.pptx
atharvdeshpande20
Python Programming Introduction demo.ppt
Python Programming Introduction demo.pptPython Programming Introduction demo.ppt
Python Programming Introduction demo.ppt
JohariNawab
Python_Unit_1.pdf
Python_Unit_1.pdfPython_Unit_1.pdf
Python_Unit_1.pdf
alaparthi
Python (3).pdf
Python (3).pdfPython (3).pdf
Python (3).pdf
samiwaris2
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek Purushothaman
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
Likhil181
Python knowledge ,......................
Python knowledge ,......................Python knowledge ,......................
Python knowledge ,......................
sabith777a
CH6 - Fundamentals of Python.pptx
CH6 - Fundamentals of Python.pptxCH6 - Fundamentals of Python.pptx
CH6 - Fundamentals of Python.pptx
EloAOgardo
Biswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptxBiswa Sir Python Fundamentals.pptx
Biswa Sir Python Fundamentals.pptx
BiswambarBehera5

Recently uploaded (20)

FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAMDUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
vlckovar
Essentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok SonawalaEssentials of a Good PMO, presented by Aalok Sonawala
Essentials of a Good PMO, presented by Aalok Sonawala
Association for Project Management
The Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, Tulu
The Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, TuluThe Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, Tulu
The Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, Tulu
DrIArulAram
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
The Broccoli Dog's inner voice (look A)
The Broccoli Dog's inner voice  (look A)The Broccoli Dog's inner voice  (look A)
The Broccoli Dog's inner voice (look A)
merasan
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷sHow to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
Celine George
Chapter 3. Social Responsibility and Ethics in Strategic Management.pptx
Chapter 3. Social Responsibility and Ethics in Strategic Management.pptxChapter 3. Social Responsibility and Ethics in Strategic Management.pptx
Chapter 3. Social Responsibility and Ethics in Strategic Management.pptx
Rommel Regala
How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18
Celine George
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
Kaun TALHA quiz Finals -- El Dorado 2025
Kaun TALHA quiz Finals -- El Dorado 2025Kaun TALHA quiz Finals -- El Dorado 2025
Kaun TALHA quiz Finals -- El Dorado 2025
Conquiztadors- the Quiz Society of Sri Venkateswara College
EDL 290F Week 3 - Mountaintop Views (2025).pdf
EDL 290F Week 3  - Mountaintop Views (2025).pdfEDL 290F Week 3  - Mountaintop Views (2025).pdf
EDL 290F Week 3 - Mountaintop Views (2025).pdf
Liz Walsh-Trevino
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
QuickBooks Desktop to QuickBooks Online How to Make the Move
QuickBooks Desktop to QuickBooks Online  How to Make the MoveQuickBooks Desktop to QuickBooks Online  How to Make the Move
QuickBooks Desktop to QuickBooks Online How to Make the Move
TechSoup
Adventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil SirAdventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil Sir
GUJARATCOMMERCECOLLE
Useful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷sUseful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷s
Celine George
Mate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptxMate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptx
Liny Jenifer
A PPT on the First Three chapters of Wings of Fire
A PPT on the First Three chapters of Wings of FireA PPT on the First Three chapters of Wings of Fire
A PPT on the First Three chapters of Wings of Fire
Beena E S
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
English 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom ObsEnglish 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom Obs
NerissaMendez1
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptxFESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
FESTIVAL: SINULOG & THINGYAN-LESSON 4.pptx
DanmarieMuli1
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAMDUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
DUBLIN PROGRAM DUBLIN PROGRAM DUBLIN PROGRAM
vlckovar
The Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, Tulu
The Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, TuluThe Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, Tulu
The Dravidian Languages: Tamil, Telugu, Kannada, Malayalam, Brahui, Kuvi, Tulu
DrIArulAram
N.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity BriefingN.C. DPI's 2023 Language Diversity Briefing
N.C. DPI's 2023 Language Diversity Briefing
Mebane Rash
The Broccoli Dog's inner voice (look A)
The Broccoli Dog's inner voice  (look A)The Broccoli Dog's inner voice  (look A)
The Broccoli Dog's inner voice (look A)
merasan
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷sHow to use Init Hooks in Odoo 18 - Odoo 際際滷s
How to use Init Hooks in Odoo 18 - Odoo 際際滷s
Celine George
Chapter 3. Social Responsibility and Ethics in Strategic Management.pptx
Chapter 3. Social Responsibility and Ethics in Strategic Management.pptxChapter 3. Social Responsibility and Ethics in Strategic Management.pptx
Chapter 3. Social Responsibility and Ethics in Strategic Management.pptx
Rommel Regala
How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18How to attach file using upload button Odoo 18
How to attach file using upload button Odoo 18
Celine George
How to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of SaleHow to Configure Restaurants in Odoo 17 Point of Sale
How to Configure Restaurants in Odoo 17 Point of Sale
Celine George
EDL 290F Week 3 - Mountaintop Views (2025).pdf
EDL 290F Week 3  - Mountaintop Views (2025).pdfEDL 290F Week 3  - Mountaintop Views (2025).pdf
EDL 290F Week 3 - Mountaintop Views (2025).pdf
Liz Walsh-Trevino
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1 2024  Lesson Plan M1...
Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1 2024 Lesson Plan M1...
pinkdvil200
QuickBooks Desktop to QuickBooks Online How to Make the Move
QuickBooks Desktop to QuickBooks Online  How to Make the MoveQuickBooks Desktop to QuickBooks Online  How to Make the Move
QuickBooks Desktop to QuickBooks Online How to Make the Move
TechSoup
Adventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil SirAdventure Activities Final By H R Gohil Sir
Adventure Activities Final By H R Gohil Sir
GUJARATCOMMERCECOLLE
Useful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷sUseful environment methods in Odoo 18 - Odoo 際際滷s
Useful environment methods in Odoo 18 - Odoo 際際滷s
Celine George
Mate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptxMate, a short story by Kate Grenvile.pptx
Mate, a short story by Kate Grenvile.pptx
Liny Jenifer
A PPT on the First Three chapters of Wings of Fire
A PPT on the First Three chapters of Wings of FireA PPT on the First Three chapters of Wings of Fire
A PPT on the First Three chapters of Wings of Fire
Beena E S
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Blind Spots in AI and Formulation Science Knowledge Pyramid (Updated Perspect...
Ajaz Hussain
English 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom ObsEnglish 4 Quarter 4 Week 4 Classroom Obs
English 4 Quarter 4 Week 4 Classroom Obs
NerissaMendez1

11-unit1chapter02pythonfundamentals-180823043011.pptx

  • 2. Previous Knowledge Testing 1. Who developed Python? Guido Van Rossum 2. Name the Pythons two working mode. Interactive & Script 3. Python programs are stored in files with _________ extension. .py extension 4. Python is the fastest language. True / false False 5. Which statement is used to display output on the screen?
  • 3. Print statement Syntax: print( <objects to be printed in quotes>) For example: print( Computer Science ) Output : Computer Science
  • 4. Print statement Arguments inside print statement: sep & end Sep is used to separate word eg. x,y=10,20 print(x , y) Output : 10 20
  • 5. Print statement Arguments inside print statement: sep & end end is used to separate word eg. x,y=10,20 print(x) print(y) Output : 10 20 print(x, end = )
  • 7. 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++. Let us learn the basic elements of python programming
  • 9. PYTHON CHARACTER SET What is Character Set? Character set is identifying elements a bunch of in the programming language.
  • 11. PYTHON CHARACTER SET PYTHON CHARACTER SET Letters:- A-Z, a-z Digits:- 0 to 9 Special Symbols:- space + - / ( ) [ ] = ! = < > , $ # ; : ? & White Spaces:- Blank Space , Horizontal Tab, Vertical tab, Carriage Return. Other Characters:- Python can process all 256 ASCII and Unicode Characters.
  • 13. What is Token or lexical unit?
  • 14. TOKENS OR LEXICAL UNIT What is Token? Individual elements that are identified by programming language are called tokens or lexical unit.
  • 16. TOKENS / LEXICAL UNITS TOKENS 1. Key Word s 2. Identifiers 3. Literals 4. Operators. 5. Punctuators
  • 17. What is Keyword or reserved word?
  • 18. 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. 1. Keyword/Reserved Word
  • 19. Some Keywords of Python Language
  • 20. Some Keywords of Python Language and assert break continue del else exe c class def elif excep t finally from
  • 21. Some Keywords of Python Language global if import in is lambda not or pass print raise return try while with yield
  • 22. What is an identifier?
  • 23. 2. IDENTIFIERS What is an identifier? A Python Identifier is a name given to a function, class, variable, module, or other objects that youll be using in your Python program. In short, its a name appeared in the program. For example: a, b, c a b and c are the identifiers and a b & c and , are the
  • 25. PYTHON NAMING CONVENTIONS the python naming What are conventions? 1. An identifier can be a combination of uppercase letters, lowercase letters, underscores, and digits (0-9). Hence, the following are valid identifiers: myClass, my_variable, var_1, and print_hello_world.
  • 26. PYTHON NAMING CONVENTIONS What are the python naming conventions? 2. The first character must be letter. 3. Special characters such as %, @, and $ are not allowed within identifiers. 4. An identifier should not begin with a number. Hence, 2variable is not valid, but variable2 is acceptable.
  • 27. the python naming What are conventions? 5. Python is a case-sensitive language and this behaviour extends to identifiers. Thus, Labour and labour are two distinct identifiers in Python. 6. You cannot use Python keywords as identifiers. PYTHON NAMING CONVENTIONS
  • 28. the python naming What are conventions? 7. You cannot use Python keywords as identifiers. 8. You can use underscores to separate multiple words in your identifier. PYTHON NAMING CONVENTIONS
  • 29. SOME VALID IDENTIFIERS: Myfile1 y3m9d3 MYFILE DATE9_7_8 _xs _FXd SOME INVALID IDENTIFIERS: MY-REC 28dre break elif false del PYTHON NAMING CONVENTIONS
  • 30. Competency Based Question 1. Write Instructions in python to get the following result: (Do it in both interactive mode and script mode) I am a student of KV Barabanki I live in Barabanki And I love Barabanki. Barabanki is 20 KM away from Lucknow This Place is famous for Dewa Sharif
  • 31. HOME WORK 1. What are tokens in python? How many tokens are allowed in Python? 2. How keyword are different from identifiers? 3. Application based Question: a,b,c = 2,8,9 print(a,b,c) print(b,c,a)
  • 33. 3. LITERALS / CONSTANT VALUES What is literals? Literals are also called as constants or constant values these are the values which never change during the execution of program.
  • 34. What are the types of literals?
  • 35. TYPES OF LITERALS / CONSTANT VALUES What are the 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.
  • 37. 1. STRING LITERALS OR CONSTANTS What is string? Sequence of letters enclosed in quotes is called string or string literal or constant. both form of Pythonsupports quotes i.e. Hel lo Hello
  • 39. REPRESENTATION OF STRING Forward Indexing >>> s = Hello Python This is how Python would index the string: Backward Indexing
  • 40. REPRESENTATION OF STRING To access the first character on the string you just created, type and enter the variable name s and the index 0 within square brackets like this: >>>s[0] Youll get this output: H
  • 41. REPRESENTATION OF STRING To access the last character, you can use this expression: >>>s[len(s)-1] Youll get the output: n Len() function is used to find the length of the string.
  • 42. REPRESENTATION OF STRING The expression introduces you to the len function. There is actually an easier way to access the last item on the string: >>>s[-1] n To access the penultimate character: >>>s[-2] o
  • 43. TYPES OF STRINGS What are the types of strings supported in python? Python supports two ways of representation of strings: 1) Single Line Strings. 2) Multi Line Strings.
  • 45. SINGLE LINE STRINGS Strings created using single quote or double quote must end in one line are called single line strings For Example: Item=Compu ter Or Item= Computer
  • 46. 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. For instance: Item = Key board
  • 48. SIZE OF STRINGS abc ab Raamas Laptop Size is 1 ( is an escape sequence) size is 3 size is 2 size is 13
  • 50. STRINGS WITH TRIPLE QUOTES For multi line strings created by triple quotes, while calculating size, the EOL(End of Line) character at the end of line is also counted. For instance: Str2=x y Z Enter keys are considered as EOL so size of str2 is 5
  • 52. ESCAPE SEQUENCES Back Slash Single Quote () Double Quote ()
  • 53. ESCAPE SEQUENCES ASCII Bell ASCII Backspace ASCII Formfeed a b f
  • 54. ESCAPE SEQUENCES New Line Carriage return Horizontal Tab n r t
  • 55. ESCAPE SEQUENCES Vertical Tab 16 bit hex value Octal Value t x ooo
  • 66. 16 bit Hex Val x
  • 67. Octal Value ooo Note: ooo represents 3 octal digits.
  • 68. 2. NUMERICAL LITERALS Numerical Literals have the following types: int or integers float Complex - Whole numbers - real values - Complex numbers
  • 69. 2. NUMERICAL LITERALS Numerical Literals have the following types: int or integers float Complex - Whole numbers - real values - Complex numbers
  • 70. INTEGER LITERALS OR CONSTANTS Decimal Integer Literals: Any whole number (+ve) or (-ve).
  • 71. INTEGER LITERALS OR CONSTANTS Octal Integer Literals(base 8): A Sequence of digits starting with 0O (digit zero followed by letter o) is taken to be an Octal Integer Literals.
  • 72. INTEGER LITERALS OR CONSTANTS Hexadecimal Integer Literals (base 16): Sequence of digits preceded by ox or OX is hexadecimal integer literals
  • 73. INTEGER LITERALS OR CONSTANTS Binary literals (base 2): To signify binary literals, youll use the prefix 0B or 0b (zero and uppercase or lowercase b).
  • 74. Converting Integers to their String Representation
  • 75. To convert an integer into its string representation, you can use the functions hex(), bin(), and oct(). To convert the integer 7 to its octal literal, type and enter oct(7) on the command prompt. Youll get the output 0o7: oct ( )
  • 76. Here is what happens when you convert the integer 2572 to a hexadecimal literal: hex ( )
  • 77. see what happens when you use the bin() function to convert the integer 12 to its binary string: bin ( )
  • 78. FLOATING POINT LITERALS OR CONSTANTS
  • 79. FLOATING POINT LITERALS OR CONSTANTS Floating point literals are also called as real literals having fractional part. These may be written in one of the two forms: 1. Fractional Form: for example 15.75 2. Exponent Form: It consists of two parts Mantissa and Exponent. for example 5.8 can be represented as 0.58 x 10-1 = 0.58E01.
  • 80. FLOATING POINT LITERALS OR CONSTANTS Float type
  • 81. BOOLEAN LITERALS OR CONSTANTS.
  • 82. 3) BOOLEAN LITERALS OR CONSTANTS. A Boolean literal in python is used to represent the Boolean values (true or false).
  • 84. 4) SPECIAL LITERAL NONE The None literal is used to indicate absence of value. For example: val = None
  • 86. 5) LITERAL COLLECTIONS Python supports literal collections also such as tuple and lists ..etc It will be to complex to discuss as we are in the beginning, subsequent chapters we will cover literal collections.
  • 88. OPERATORS What is an operator? Operators are tokens that trigger some computation when applied to a variable. that What is Unary Operator? Unary operators are those operators require one operand to operate upon. Unary Operators: + - ~ not Unary Plus Unary Minus Bitwise Compliment Logical Negation
  • 89. OPERATORS What is Binary Operator? Binary operators are those operators that require two operands to operate upon. Binary Operators: + - * / % ** // Addition Subtraction Multiplication Division Remainder or Modulus Exponent. Floor Division
  • 90. OPERATORS What is Binary Operator? Binary operators are those operators that require two operands to operate upon. Binary Operators: + - * / % ** // Addition Subtraction Multiplication Division Remainder or Modulus Exponent. Floor Division
  • 91. OPERATORS Bitwise Operators: & ^ | Bitwise AND Bitwise Exclusive OR Bitwise OR Shift Operators: << >> Shift Left Shift Right
  • 92. OPERATORS Relational Operators: < > <= >= == != Less than Greater than Less than equal to Greater than equal to Equal to Not equal to Logical Operators: and or Logical AND Logical OR
  • 97. BITWISE AND & EXAMPLE
  • 98. BITWISE AND OPERATO R BITWISE AND & OPERATOR EXAMPLE & operator picks bits exists in both the operands (common)
  • 99. BITWISE OR | EXAMPLE
  • 100. BITWISE OR | OPERATOR BITWISE OR | OPERATOR EXAMPLE | operator picks bits exists in either the operands ( any one or both )
  • 101. BITWISE OR EXCLUSIVE ^ EXAMPLE
  • 102. BITWISE EXCLUSIVE OR ^ OPERATOR EXAMPLE BITWISE ^ OPERATOR It picks up bit if it is one operand not in both (uncommon)
  • 104. BITWISE ONEs COMPLIMENT ~ OPERATOR EXAMPLE
  • 105. BINARY ONEs COMPLIMENT ~ OPERATOR EXAMPLE It is the unary operator which has a flipping effect.
  • 106. << BINARY LEFT SHIFT OPERATOR EXAMPLE
  • 107. BINARY << LEFT SHIFT EXAMPLE The first operands value is moved left by the number of bits specified by the second operand.
  • 108. << BINARY RIGHT SHIFT OPERATOR EXAMPLE
  • 109. BINARY >> RIGHT SHIFT EXAMPLE The first operands value is moved right by the number of bits specified by the second operand.
  • 111. OPERATORS Assignment Operators: = *= /= += -= %= **= //= Assignment Operator Assign Product Assign Quotient Assign Sum Assign Minus Assign Remainder Assign Exponent Assign Floor Division.
  • 113. BINARY >> RIGHT SHIFT EXAMPLE
  • 114. OPERATORS Membership Operators: in weather variable in sequence. not in weather variable not in sequence
  • 117. PUNCTUATORS Punctuators are also called as separators The Followings are used as punctuators: Brackets [ ] Parentheses ( ) Braces { } Comma , Semicolon ; Colon : Asterisk * Ellipsis = Equal Sign Pound Sign #
  • 119. GENERAL STRUCTURE OF PYTHON PROGRAM #Comments
  • 120. GENERAL STRUCTURE OF PYTHON PROGRAM
  • 121. GENERAL STRUCTURE OF PYTHON PROGRAM # Write a program to find square of given number. def sqr( num ): result= num *num print ("Square = " , result) def main(): x=int(input("Enter the number : ")) sqr(x) main() Programmer defined FUNCTION main() function Comment
  • 122. WHITE SPACE Whitespace Whitespace is meaningful in Python, especially indentation and placement of newlines. Use a newline to end a line of code. Use when must go to next line prematurely. No braces { } to mark blocks of code in Python
  • 124. WHITE SPACE Use consistent indentation instead. The first line with less indentation is outside of the block. The first line with more indentation starts a nested block. Often a colon appears at the start of a new block. (E.g. for function and class definitions.).
  • 126. COMMENTS Comments are non executable statements in a program. Single line comment always starts with # Multiline comment will be in triple quotes. For example write a program to find the simple interest . Note: Triple apostrophe is called docstrings.
  • 128. STATEMENTS In computer terminology statement refers to an instruction. Program contains several statements. A collection of statements makes program Another name for a program is code.
  • 130. FUNCTIONS What is function? Function is a self contained program segment which carries out some specific well defined task. For Example: def sqr( num ): result= num *num print ("Square = " , result) sqr()
  • 132. PYTHON PROGRAMMING CONVENTIONS Statement Termination: python does not use any symbol to terminate the statement. Maximum Line Length: Line Length be maximum 79 characters. Whitespaces: you should always have whitespace around operators but not with parenthesis.
  • 133. PYTHON PROGRAMMING CONVENTIONS Block or Code Block: A group of statements which are part of another statement or function is called Block or Code Block. Case Sensitive: Python is case sensitive.
  • 135. VARIABLES AND ASSIGNMENTS Named labels are called variables. For example: marks =86 78 79 80 81 82 83 84 85 86 87 2000 2016 2018 2026 2032 2044 2048 2050 2054 2068 marks refers to location 2054
  • 136. VARIABLES AND ASSIGNMENTS Now marks = 81 78 79 80 81 82 83 84 85 86 87 2000 2016 2018 2026 2032 2044 2048 2050 2054 2068 marks refers to location 2026
  • 137. VARIABLES AND ASSIGNMENTS lvalues & rvalues: Lvalue:Expressions that is on LHS (Left Hand Side) is called Lvalue. Rvalue: Expressions that is on RHS (Right Hand Side) is called Rvalue.
  • 138. VARIABLES AND ASSIGNMENTS Multiple Assignments Python is very versatile with assignment statements. to multiple 1. Assigning same value variables: a=b=c=d=e=10
  • 139. VARIABLES AND ASSIGNMENTS Multiple Assignments 2. Assigning Multiple values to multiple variables: p,q,r =5,10,15 print(q, r) will print 10 15 p,q=q,p print (p,q) will print 10 5
  • 140. VARIABLES AND ASSIGNMENTS Multiple Assignments 2. Assigning Multiple values to multiple variables: a,b,c = 5,10,7 b,c,a = a+1, b+2, c-1 print(a,b,c) will print 6 6 12 Now, X=10
  • 141. VARIABLES AND ASSIGNMENTS Multiple Assignments Expressions separated by commas are evaluated from left to right. Now, x = 10 y,y = x+2,x+5 y,y = 12,15 First It will assign y = 12 then y = 15 So print(y) will print 15
  • 142. VARIABLES AND ASSIGNMENTS Dynamic Typing: A variable pointing to a value of certain type can be made to point to a value/object this is called Dynamic of different type Typing. x=10 print(x) x= Hello World print(x)
  • 143. VARIABLES AND ASSIGNMENTS Output will be 10 Hello World 10 10 Hello World x x
  • 144. VARIABLES AND ASSIGNMENTS Caution with Dynamic Typing: x = day y = x/2 Error! String can not be divided.
  • 145. VARIABLES AND ASSIGNMENTS type() function: To know the data type of a value which is pointing use type ( ) >>>a=10 >>>type(a) <class int> >>>a=20.4 >>>type(a) <class float> Type returned as integer Type returned as float
  • 146. VARIABLES AND ASSIGNMENTS type() function: To know the data type of a value which is pointing use type ( ) >>>a=Hello >>>type(a) <class str> Type returned as string
  • 147. INPUT ( ) FUNCTION
  • 148. INPUT ( ) FUNCTION Input( ) Function is a built in function of python used to read values from the user The general format or syntax of the input() is: Variable_to_hold_the_value=input(mess age) For Example: Where, variable location variable_to_Hold_the_Value is a which is the label for a memory where the value is stored.
  • 149. INPUT ( ) FUNCTION For Example: p = input(Enter the value) x = int(input(Enter x value)) reads the value and converts it in to integer type data or value. y=float(input(Enter y value)) reads the value and converts it in to float type data or value.
  • 150. INPUT ( ) FUNCTION int ( ) and float ( ) Functions: Python offerstwo functions to be used with input( ) to convert the received values: Example 1: >>age = int(input(Enter age)) Example 2: >>sal=float(input(Enter salary))
  • 151. PRINT ( ) FUNCTION
  • 152. PRINT ( ) FUNCTION print( ) Function is a built in function of python used to display the values on the screen The general format or syntax of the input() is: print(*objects, sep=' ', end='n', file=sys.stdout, flush=False) The print function can print an arbitrary number of values ("value1, value2, ..."), which are separated by commas. These values are separated by blanks. In the following example we can see two print calls. We are printing two values in both cases, i.e. a string and a float number:
  • 153. PRINT ( ) FUNCTION print() Parameters: objects - object to the printed. * indicates that there may be more than one object sep - objects are separated by sep. Default value: ' end - end is printed at last file - must be an object with write(string) method. If omitted it, sys.stdout will be used which prints objects on the screen. flush - If True, the stream is forcibly flushed. Default value: False
  • 154. PRINT ( ) FUNCTION Example 1: How print() works in Python? print("Python is fun.") a = 5 #Two objects are passed: print("a =", a) b = a # Three objects are passed: print('a =', a, '= b) Output Python is fun. a = 5 a = 5 = b
  • 155. PRINT ( ) FUNCTION Example 2: How print() works in Python? >>> print("a = ", a) a = 3.564 >>> print("a = n", a) a = 3.564 >>>