PYTHON
FUNDAMENTALS
Python Character
Set
Is a set of valid characters that python can recognize. A
character represent letters, digits or any symbol. Python
support UNICODE encoding standard. Following are the
Python character set
 Letter
s
 Digits
: A-Z, a-z
: 0-9
 Special symbols :space +-*/()~`!@#$%^ & [{
]};:‟”,<.>/?
 White spaces : Blank space, Enter,
Tab
 Other character : python can process all
ASCII and UNICODE as a part of data or literal
TOKENS
Tokens or lexical units or lexical elements: The
smallest individual unit in a program is known as
Tokens. Python has following tokens:
 Keywords
 Identifiers(Name)
 Literals
 Operators
 Punctuators
KEYWORDS
VINOD KUMAR VERMA, PGT(CS), KV OEF
KANPUR &
SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR
Keywords are the reserved words and have
special meaning for python interpreter. Every
keyword is assigned specific work and it can be
used only for that purpose.
A partial list of keywords in Python is
IDENTIFIERS
Are the names given to variables, objects,
classes, functions etc.
Identifier forming rules of Python are :
 Is an arbitrarily long sequence of letters and digits
 The first character must be letter or underscore
 Upper and lower case are different
 The digits 0-9 are allowed except for first character
 It must not be a keyword
 No special characters are allowed other than underscore
is allowed.
 Space not allowed
GradePay
GRADEPAY
File_12_2024
_ismarried
JAMES007
_to_update
The following are some valid identifiers
The following are some invalid identifiers
Variable
s
 Variables are named temporary location used to
store values which can be further used in
calculations, printing result etc. Every variable
must have its own Identity, type and value.
Variable in python is created by simply
assigning value of desired type to them.
 For e.g
 Num = 100
 Name=“JamesF
Lvalues and Rvalues
 Lvalue : expression that comes on the Left
hand Side of Assignment.
 Rvalue : expression that comes on the
Right hand Sideof Assignment
Lvalue refers to object to which you can assign value. It
refers to memory location. It can appear LHS or RHS of
assignment
Rvalue refers to the value we assign to any variable. It
can appear on RHS of assignment
Lvalues and
Rvalues
For example (valid use of Lvalue and Rvalue)
x = 100
y = 200
Invalid use of Lvalue and Rvalue
100 = x
200 = y
a+b = c
Note: values cannot comes to the left of assignment.
LHS must be a
memory location
Multiple
Assignments
 Python is very versatile with assignments. Let‟s see in how
different ways we can use assignment in Python:
1. Assigning same value to multiple variable
a = b = c = 50
2. Assigning multiple values to multiple
variable a,b,c = 11,22,33
Note: While assigning values through multiple
assignment, remember that Python first evaluates
the RHS and then assigns them to LHS
Examples:
#Statement 1
#Statement 2
x,y,z = 10,20,30
z,y,x = x+1,z+10,y-10
print(x,y,z)
Output will be
10 40 11
Multiple
Assignments
Now guess the output of following code fragment
x,y = 7,9
y,z = x-2, x+10
print(x,y,z)
Let us take another example
y, y = 10, 20
In above code first it will assign 10 to y and again it assign 20 to
y, so if you print the value of y it will print 20
Now guess the output of following code
x, x = 100,200
y,y = x + 100, x +200
print(x,y)
Variable
definition
 Variable in python is create when you assign
value to it
i.e. a variable is not create in memory until
some value is assigned to it.
 Let us take as example(if we execute the
following code) print(x)
Python will show an error „x not defined
‟
So to correct the above
code: x=0
print(x)
#now it will show no
Literals /
Values
 Literals are data items that have a fixed
value. Python supports several kinds of
literals:
🞑 String Literal
🞑 Numeric Literals
🞑 Boolean Literals
🞑 Special Literals – None
🞑 Literal Collections
String Literals
 It is a collection of character(s) enclosed in a
double or single quotes
 Examples of String literals
🞑 “Python”
🞑 'Mogambo'
In Python both single character or multiple
characters enclosed in quotes such as “kv”,
‟*‟,”+” are treated as same
String type in
Python
 Python allows you to have two string types:
🞑 Single Line Strings
 The string we create using single or double quotes
are normally single-line string i.e. they must
terminate in one line.
 For e.g if you type as
 Name="KV and press enter
 Python we show you an error “EOL while scanning
string literal”
 The reason is quite clear, Python by default creates
single-line string with both single quotes and it must
terminate in the same line by quotes
String type in Python
 Multiline String
🞑 Some times we need to store some text across
multiple lines. For that Python offers multiline
string.
🞑By typing text in triple quotation marks
for e.g.
>>> Address="""1/7 Preet Vihar New Delhi
India"""
>>> print(Address) 1/7 Preet Vihar New
Delhi
India
>>> Address
'1/7 Preet ViharnNew DelhinIndia'
Non-Graphic (Escape) characters
 They are the special characters which cannot be type
directly from keyboard like backspace, tabs, enter etc.
 These are represented by escape characters. The
sequence of characters after a backslash is known as
an escape sequence.
Escape
Sequence
What it does Escape
Sequence
What it does
 Backslash r Carriage return
‟ Single quotes t Horizontal tab
” Double quotes uxxxx Hexadecima
l value(16
bit)
a ASCII bell Uxxxx Hexadecima
l value(32
bit)
b Back Space v vertical tab
Numeric
Literals
 The numeric literals in Python can belong to any of
the following numerical types:
1)Integer Literals: it contain at least one digit and must not
contain decimal point. It may contain (+) or (-) sign.

2) Floating point Literals: also known as real literals. Real
literals are numbers having fractional parts. It is
represented in two forms Fractional Form or
Exponent Form
 Fractional Form: it is signed or unsigned with decimal point
🞑 For e.g. 12.0, -15.86, 0.5, 10. (will represent 10.0)
 Exponent Part: it consists of two parts “Mantissa” and
“Exponent”.
🞑 For e.g. 10.5 can be represented as 0.105 x 102 = 0.105E02
where
0.105 is mantissa and 02 (after letter E) is exponent
3) Complex: Complex number in python is made up of two floating
point values, one each for real and imaginary part. For accessing
different parts of variable (object) x; we will use x.real and x.image.
Imaginary part of the number is represented by “j” instead of “I”,
so 1+0j denotes zero imaginary part.
Example
>>> x = 1+0j
>>> print
x.real,x.imag 1.0 0.0
Example
>>> y = 9-5j
>>> print y.real,
y.imag 9.0 -5.0
Numeric Literals
Boolean
Literals
A Boolean literals in Python is used to represent one of
the two Boolean values i.e. True or False
These are the only two values supported for Boolean
Literals For e.g.
>>> isMarried=True
>>> type(isMarried)
<class 'bool'>
Special Literals
None
Python has one special literal, which is None. It indicate
absence of value. In other languages it is knows as NULL.
It is also used to indicate the end of lists in Python.
>>> salary=None
>>> type(salary)
<class 'NoneType'>
Simple Input and
Output
 In python we can take input from user using the
built-in function input().
 Syntax
variable = input(<message to display>)
Note: value taken by input() function will always be of String type,
so by default you will not be able to perform any arithmetic
operation on variable.
>>> marks=input("Enter your
marks ") Enter your marks 100
>>> type(marks)
<class 'str'>
Here you can see even we are entering value 100 but it will be
treated as string and will not allow any arithmetic operation
Operator
s
 Are symbol that perform specific operation
when applied on variables. Take a look at the
expression: (Operator)
10 + 25 (Operands) Above
statement is an expression
(combination of operator and
operands)
i.e. operator operates on operand.
some operator requires two operand and some
requires only one operand to operate
Types of
Operators
 Unary operators: are those operators that
require one operand to operate upon.
Following are some unary operators:
Operator Purpose
+ Unary plus
- Unary minus
~ Bitwise
complement
Not Logical negation
Types of
Operators
 Binary Operators:are those
operators
that
require two upon.
Following are some Binary
operand to
operate
operators:
1. Arithmetic
Operators
Operator Action
+ Addition
- Subtraction
* Multiplication
/ Division
% Remainder
** Exponent
/ / Floor division
Exampl
e
>>> num1=20
>>> num2=7
>>> val = num1 %
num2
>>>
print(val) 6
>>> val =
2**4
>>>
print(val) 16
>>> val =
num1 /
num2
>>> print(val)
2.85714285714285
7
>>> val = num1 / /
Bitwise
operator
Operator Purpose Action
& Bitwise AND Return 1 if both
inputs are 1
^ Bitwise XOR Return 1, if
the number
of 1 in
input is in
odd
| Bitwise OR Return 1 if
any input is
1
Bitwise operator
works on the binary
value of number not
on the actual value.
For example if 5 is
passed to these
operator it will work
on 101 not on 5.
Binary of
5 is 101, and return
the result in decimal
not in binary.
Identity
Operators
Operators Purpose
<< Shift left
>> Shift right
Operators Purpose
is Is the Identity same?
is not Is the identity not same?
Relational
Operators
Operators Purpose
< Less than
> Greater than
<= Less than or Equal to
>= Greater than or Equal to
== Equal to
!= Not equal to
Logical
Operators
Operators Purpose
and Logical AND
or Logical OR
not Logical NOT
Assignment
Operators
Operators Purpose
= Assignment
/ = Assign quotient
+= Assign sum
-= Assign difference
*= Assign product
**= Assign Exponent
/ / = Assign Floor division
Membership
Operators
Operators Purpose
in Whether variable
in sequence
not in Whether variable not
in sequence
Punctuato
rs
 Punctuators are symbols that are used in
programming languages to organize sentence
structure, and indicate the rhythm and emphasis
of expressions, statements, and program
structure.
 Common punctuators are: „ “ # $ @ []{}=:;(),.
Comments
addition
al
informationwritten in
a
 Comments
are program
which
is not executed by interpreter
i.e.
ignored by Interpreter. Comment
contains information regarding statements
used, program flow, etc.
 Comments in Python begins from #
 Python supports 3 ways to enter comments:
1. Full line comment
2. Inline comment
3. Multiline comment
Comment
s
 Full line comment
Example:
#This is program of volume of cylinder
 Inline comment
Example
# calculating area of rectangle
area = length*breadth
 Multiline comment
Example 1 (using #)
# Program name: area of circle # Date: 09/05/24
#Language : Python
Comments
 Multiline comment (using “ “ “) triple quotes
Example
“ “ “
Program name : swapping of two number
Date
Logic
: 09/05/24
: by using third
variable ” ” ”
Simple Input and
Output
>>> salary=input("Enter your salary ")
Enter your salary 5000
>>> bonus = salary*20/100
Traceback (most recent call
last):
File "<stdin>", line 1, in
<module>
TypeError: unsupported
operand type(s) for /: 'str' and
'int'
Reading / Input of
Numbers
 Now we are aware that input() function
value will always be of string type, but what
to do if we want number to be entered.
The solution to this problem is to convert
values of input() to numeric type using int()
or float() function.
Possible chances of error while
taking input as numbers
1. Entering float value while converting to int
>>> num1=int(input("Enter marks "))
Enter marks 100.5
Traceback (most recent call last): File "<stdin>", line 1,
in <module>
ValueError: invalid literal for int() with base 10: '100.5‘
2. Entering of values in words rather than numeric
>>> age=int(input("What is your age "))
What is your age Eighteen
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: Eighteen'
Possible chances of error while
taking input as numbers
3. While input for float value must be compatible.
For e.g. Example 1
>>> percentage=float(input("Enter
percentage ")) Enter percentage 12.5.6
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to
float: '12.5.6'
Example 2
>>> percentage=float(input("Enter
percentage ")) Enter percentage 100
percent
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: could not convert string to
float: „100 percent'
Program
1
Open a new script file and type the following
code:
num1=int(input("Enter Number 1
")) num2=int(input("Enter Number
2 ")) num3 = num1 + num2
print("Result =",num3)
Save and execute by F5 and
observe the result
Let us write few
programs
 WAP to enter length and breadth and calculate
area of rectangle
 WAP to enter radius of circle and calculate
area of circle
 WAP to enter Name, marks of 5 subject and
calculate total & percentage of student
 WAP to enter distance in feet and convert it
into inches
 WAP to enter value of temperature in
Fahrenheit and convert it into Celsius.
 WAP to enter radius and height of cylinder
and calculate volume of cylinder.
Just a
minute…
 What is the difference between keywords
and identifiers
 What are literals in Python? How many types
of literals in python?
 How many types of String in python?
 What are the different ways to declare
multiline String?
 What is the error in following python
program:
print(“Name is”, name)
Just a
minute…
 Why the following code is giving
error?
Name="James"
Salary=2000
0 Dept="IT"
print("Name is ",Name)
print(Dept)
print("Salary is ",salary)
Just a
minute…
 WAP to obtain temperature in Celsius and
convert it into
Fahrenheit.
 What will be the output of
following code: x, y = 6,8
x,y = y, x+2
print(x,y)
 What will be the output of
following code: x,y = 7,2
x,y,x = x+4, y+6,
x+100 print(x,y)

More Related Content

PPTX
CH-3 FEATURES OF PYTHON, data types token
PPTX
GRADE 11 Chapter 5 - Python Fundamentals.pptx
PDF
Module1PPT.pdf ,introduction to python programing
PPTX
11 Unit 1 Chapter 02 Python Fundamentals
PPTX
Python Programming | JNTUK | UNIT 1 | Lecture 4
PPTX
IMP PPT- Python programming fundamentals.pptx
PPT
Python programming unit 2 -Slides-3.ppt
PPTX
Chapter 1 Python Revision (1).pptx the royal ac acemy
CH-3 FEATURES OF PYTHON, data types token
GRADE 11 Chapter 5 - Python Fundamentals.pptx
Module1PPT.pdf ,introduction to python programing
11 Unit 1 Chapter 02 Python Fundamentals
Python Programming | JNTUK | UNIT 1 | Lecture 4
IMP PPT- Python programming fundamentals.pptx
Python programming unit 2 -Slides-3.ppt
Chapter 1 Python Revision (1).pptx the royal ac acemy

Similar to python fudmentalsYYour score increaseases (20)

PPTX
Review old Pygame made using python programming.pptx
PPTX
Python ppt
PPTX
unit1.pptx for python programming CSE department
PPTX
presentation_python_7_1569170870_375360.pptx
PPTX
Biswa Sir Python Fundamentals.pptx
PPTX
PPT_1_9102501a-a7a1-493e-818f-cf699918bbf6.pptx
PPTX
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
PPTX
Python unit 1 (1).pptx
PPTX
chapter_5_ppt_em_220247.pptx
PPTX
CH6 - Fundamentals of Python.pptx
PPTX
unit1 python.pptx
PPTX
parts_of_python_programming_language.pptx
PPTX
Chapter 6 Python Fundamentals.pptx
PPTX
Chapter 6 Python Fundamentals.pptx
PDF
PPE-Module-1.2 PPE-Module-1.2 PPE-Module-1.2.pdf
PPTX
MODULE. .pptx
PDF
Python lecture 03
PPTX
Chapter 9 python fundamentals
PPTX
PYTHON PROGRAMMING PROBLEM SOLVING PPT DOCUMENTS PPT
PDF
03-Variables, Expressions and Statements (1).pdf
Review old Pygame made using python programming.pptx
Python ppt
unit1.pptx for python programming CSE department
presentation_python_7_1569170870_375360.pptx
Biswa Sir Python Fundamentals.pptx
PPT_1_9102501a-a7a1-493e-818f-cf699918bbf6.pptx
Lecture-2-Python-Basic-Elements-Sep04-2018.pptx
Python unit 1 (1).pptx
chapter_5_ppt_em_220247.pptx
CH6 - Fundamentals of Python.pptx
unit1 python.pptx
parts_of_python_programming_language.pptx
Chapter 6 Python Fundamentals.pptx
Chapter 6 Python Fundamentals.pptx
PPE-Module-1.2 PPE-Module-1.2 PPE-Module-1.2.pdf
MODULE. .pptx
Python lecture 03
Chapter 9 python fundamentals
PYTHON PROGRAMMING PROBLEM SOLVING PPT DOCUMENTS PPT
03-Variables, Expressions and Statements (1).pdf
Ad

Recently uploaded (20)

PPT
Pyramid Points Lab Values Power Point(11).ppt
PDF
Zuri Health Pan-African Digital Health Innovator.pdf
PPTX
Nancy Caroline Emergency Paramedic Chapter 4
PDF
demography and familyplanning-181222172149.pdf
PDF
Essentials of Hysteroscopy at World Laparoscopy Hospital
PPTX
Understanding The Self : 1Sexual health
PDF
health promotion and maintenance of elderly
DOCX
ch 9 botes for OB aka Pregnant women eww
PPTX
POSTURE.pptx......,............. .........
PPTX
Fever and skin rash - Approach.pptxBy Dr Gururaja R , Paediatrician. An usef...
PPTX
Nancy Caroline Emergency Paramedic Chapter 8
PPTX
Acute renal failure.pptx for BNs 2nd year
PPTX
OSTEOMYELITIS and OSTEORADIONECROSIS.pptx
PPTX
Nepal health service act.pptx by Sunil Sharma
PPTX
Full Slide Deck - SY CF Talk Adelaide 10June.pptx
PPTX
GCP GUIDELINES 2025 mmch workshop .pptx
PPTX
Nancy Caroline Emergency Paramedic Chapter 17
PPTX
Benign prostatic hyperplasia, uro anaesthesia
PPTX
Hospital Services healthcare management in india
PPTX
guidance--unit 1 semester-5 bsc nursing.
Pyramid Points Lab Values Power Point(11).ppt
Zuri Health Pan-African Digital Health Innovator.pdf
Nancy Caroline Emergency Paramedic Chapter 4
demography and familyplanning-181222172149.pdf
Essentials of Hysteroscopy at World Laparoscopy Hospital
Understanding The Self : 1Sexual health
health promotion and maintenance of elderly
ch 9 botes for OB aka Pregnant women eww
POSTURE.pptx......,............. .........
Fever and skin rash - Approach.pptxBy Dr Gururaja R , Paediatrician. An usef...
Nancy Caroline Emergency Paramedic Chapter 8
Acute renal failure.pptx for BNs 2nd year
OSTEOMYELITIS and OSTEORADIONECROSIS.pptx
Nepal health service act.pptx by Sunil Sharma
Full Slide Deck - SY CF Talk Adelaide 10June.pptx
GCP GUIDELINES 2025 mmch workshop .pptx
Nancy Caroline Emergency Paramedic Chapter 17
Benign prostatic hyperplasia, uro anaesthesia
Hospital Services healthcare management in india
guidance--unit 1 semester-5 bsc nursing.
Ad

python fudmentalsYYour score increaseases

  • 2. Python Character Set Is a set of valid characters that python can recognize. A character represent letters, digits or any symbol. Python support UNICODE encoding standard. Following are the Python character set  Letter s  Digits : A-Z, a-z : 0-9  Special symbols :space +-*/()~`!@#$%^ & [{ ]};:‟”,<.>/?  White spaces : Blank space, Enter, Tab  Other character : python can process all ASCII and UNICODE as a part of data or literal
  • 3. TOKENS Tokens or lexical units or lexical elements: The smallest individual unit in a program is known as Tokens. Python has following tokens:  Keywords  Identifiers(Name)  Literals  Operators  Punctuators
  • 4. KEYWORDS VINOD KUMAR VERMA, PGT(CS), KV OEF KANPUR & SACHIN BHARDWAJ, PGT(CS), KV NO.1 TEZPUR Keywords are the reserved words and have special meaning for python interpreter. Every keyword is assigned specific work and it can be used only for that purpose. A partial list of keywords in Python is
  • 5. IDENTIFIERS Are the names given to variables, objects, classes, functions etc. Identifier forming rules of Python are :  Is an arbitrarily long sequence of letters and digits  The first character must be letter or underscore  Upper and lower case are different  The digits 0-9 are allowed except for first character  It must not be a keyword  No special characters are allowed other than underscore is allowed.  Space not allowed
  • 6. GradePay GRADEPAY File_12_2024 _ismarried JAMES007 _to_update The following are some valid identifiers The following are some invalid identifiers
  • 7. Variable s  Variables are named temporary location used to store values which can be further used in calculations, printing result etc. Every variable must have its own Identity, type and value. Variable in python is created by simply assigning value of desired type to them.  For e.g  Num = 100  Name=“JamesF
  • 8. Lvalues and Rvalues  Lvalue : expression that comes on the Left hand Side of Assignment.  Rvalue : expression that comes on the Right hand Sideof Assignment Lvalue refers to object to which you can assign value. It refers to memory location. It can appear LHS or RHS of assignment Rvalue refers to the value we assign to any variable. It can appear on RHS of assignment
  • 9. Lvalues and Rvalues For example (valid use of Lvalue and Rvalue) x = 100 y = 200 Invalid use of Lvalue and Rvalue 100 = x 200 = y a+b = c Note: values cannot comes to the left of assignment. LHS must be a memory location
  • 10. Multiple Assignments  Python is very versatile with assignments. Let‟s see in how different ways we can use assignment in Python: 1. Assigning same value to multiple variable a = b = c = 50 2. Assigning multiple values to multiple variable a,b,c = 11,22,33 Note: While assigning values through multiple assignment, remember that Python first evaluates the RHS and then assigns them to LHS Examples: #Statement 1 #Statement 2 x,y,z = 10,20,30 z,y,x = x+1,z+10,y-10 print(x,y,z) Output will be 10 40 11
  • 11. Multiple Assignments Now guess the output of following code fragment x,y = 7,9 y,z = x-2, x+10 print(x,y,z) Let us take another example y, y = 10, 20 In above code first it will assign 10 to y and again it assign 20 to y, so if you print the value of y it will print 20 Now guess the output of following code x, x = 100,200 y,y = x + 100, x +200 print(x,y)
  • 12. Variable definition  Variable in python is create when you assign value to it i.e. a variable is not create in memory until some value is assigned to it.  Let us take as example(if we execute the following code) print(x) Python will show an error „x not defined ‟ So to correct the above code: x=0 print(x) #now it will show no
  • 13. Literals / Values  Literals are data items that have a fixed value. Python supports several kinds of literals: 🞑 String Literal 🞑 Numeric Literals 🞑 Boolean Literals 🞑 Special Literals – None 🞑 Literal Collections
  • 14. String Literals  It is a collection of character(s) enclosed in a double or single quotes  Examples of String literals 🞑 “Python” 🞑 'Mogambo' In Python both single character or multiple characters enclosed in quotes such as “kv”, ‟*‟,”+” are treated as same
  • 15. String type in Python  Python allows you to have two string types: 🞑 Single Line Strings  The string we create using single or double quotes are normally single-line string i.e. they must terminate in one line.  For e.g if you type as  Name="KV and press enter  Python we show you an error “EOL while scanning string literal”  The reason is quite clear, Python by default creates single-line string with both single quotes and it must terminate in the same line by quotes
  • 16. String type in Python  Multiline String 🞑 Some times we need to store some text across multiple lines. For that Python offers multiline string. 🞑By typing text in triple quotation marks for e.g. >>> Address="""1/7 Preet Vihar New Delhi India""" >>> print(Address) 1/7 Preet Vihar New Delhi India >>> Address '1/7 Preet ViharnNew DelhinIndia'
  • 17. Non-Graphic (Escape) characters  They are the special characters which cannot be type directly from keyboard like backspace, tabs, enter etc.  These are represented by escape characters. The sequence of characters after a backslash is known as an escape sequence. Escape Sequence What it does Escape Sequence What it does Backslash r Carriage return ‟ Single quotes t Horizontal tab ” Double quotes uxxxx Hexadecima l value(16 bit) a ASCII bell Uxxxx Hexadecima l value(32 bit) b Back Space v vertical tab
  • 18. Numeric Literals  The numeric literals in Python can belong to any of the following numerical types: 1)Integer Literals: it contain at least one digit and must not contain decimal point. It may contain (+) or (-) sign.  2) Floating point Literals: also known as real literals. Real literals are numbers having fractional parts. It is represented in two forms Fractional Form or Exponent Form  Fractional Form: it is signed or unsigned with decimal point 🞑 For e.g. 12.0, -15.86, 0.5, 10. (will represent 10.0)  Exponent Part: it consists of two parts “Mantissa” and “Exponent”. 🞑 For e.g. 10.5 can be represented as 0.105 x 102 = 0.105E02 where 0.105 is mantissa and 02 (after letter E) is exponent
  • 19. 3) Complex: Complex number in python is made up of two floating point values, one each for real and imaginary part. For accessing different parts of variable (object) x; we will use x.real and x.image. Imaginary part of the number is represented by “j” instead of “I”, so 1+0j denotes zero imaginary part. Example >>> x = 1+0j >>> print x.real,x.imag 1.0 0.0 Example >>> y = 9-5j >>> print y.real, y.imag 9.0 -5.0 Numeric Literals
  • 20. Boolean Literals A Boolean literals in Python is used to represent one of the two Boolean values i.e. True or False These are the only two values supported for Boolean Literals For e.g. >>> isMarried=True >>> type(isMarried) <class 'bool'>
  • 21. Special Literals None Python has one special literal, which is None. It indicate absence of value. In other languages it is knows as NULL. It is also used to indicate the end of lists in Python. >>> salary=None >>> type(salary) <class 'NoneType'>
  • 22. Simple Input and Output  In python we can take input from user using the built-in function input().  Syntax variable = input(<message to display>) Note: value taken by input() function will always be of String type, so by default you will not be able to perform any arithmetic operation on variable. >>> marks=input("Enter your marks ") Enter your marks 100 >>> type(marks) <class 'str'> Here you can see even we are entering value 100 but it will be treated as string and will not allow any arithmetic operation
  • 23. Operator s  Are symbol that perform specific operation when applied on variables. Take a look at the expression: (Operator) 10 + 25 (Operands) Above statement is an expression (combination of operator and operands) i.e. operator operates on operand. some operator requires two operand and some requires only one operand to operate
  • 24. Types of Operators  Unary operators: are those operators that require one operand to operate upon. Following are some unary operators: Operator Purpose + Unary plus - Unary minus ~ Bitwise complement Not Logical negation
  • 25. Types of Operators  Binary Operators:are those operators that require two upon. Following are some Binary operand to operate operators: 1. Arithmetic Operators Operator Action + Addition - Subtraction * Multiplication / Division % Remainder ** Exponent / / Floor division
  • 26. Exampl e >>> num1=20 >>> num2=7 >>> val = num1 % num2 >>> print(val) 6 >>> val = 2**4 >>> print(val) 16 >>> val = num1 / num2 >>> print(val) 2.85714285714285 7 >>> val = num1 / /
  • 27. Bitwise operator Operator Purpose Action & Bitwise AND Return 1 if both inputs are 1 ^ Bitwise XOR Return 1, if the number of 1 in input is in odd | Bitwise OR Return 1 if any input is 1 Bitwise operator works on the binary value of number not on the actual value. For example if 5 is passed to these operator it will work on 101 not on 5. Binary of 5 is 101, and return the result in decimal not in binary.
  • 28. Identity Operators Operators Purpose << Shift left >> Shift right Operators Purpose is Is the Identity same? is not Is the identity not same?
  • 29. Relational Operators Operators Purpose < Less than > Greater than <= Less than or Equal to >= Greater than or Equal to == Equal to != Not equal to
  • 30. Logical Operators Operators Purpose and Logical AND or Logical OR not Logical NOT
  • 31. Assignment Operators Operators Purpose = Assignment / = Assign quotient += Assign sum -= Assign difference *= Assign product **= Assign Exponent / / = Assign Floor division
  • 32. Membership Operators Operators Purpose in Whether variable in sequence not in Whether variable not in sequence
  • 33. Punctuato rs  Punctuators are symbols that are used in programming languages to organize sentence structure, and indicate the rhythm and emphasis of expressions, statements, and program structure.  Common punctuators are: „ “ # $ @ []{}=:;(),.
  • 34. Comments addition al informationwritten in a  Comments are program which is not executed by interpreter i.e. ignored by Interpreter. Comment contains information regarding statements used, program flow, etc.  Comments in Python begins from #  Python supports 3 ways to enter comments: 1. Full line comment 2. Inline comment 3. Multiline comment
  • 35. Comment s  Full line comment Example: #This is program of volume of cylinder  Inline comment Example # calculating area of rectangle area = length*breadth  Multiline comment Example 1 (using #) # Program name: area of circle # Date: 09/05/24 #Language : Python
  • 36. Comments  Multiline comment (using “ “ “) triple quotes Example “ “ “ Program name : swapping of two number Date Logic : 09/05/24 : by using third variable ” ” ”
  • 37. Simple Input and Output >>> salary=input("Enter your salary ") Enter your salary 5000 >>> bonus = salary*20/100 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for /: 'str' and 'int'
  • 38. Reading / Input of Numbers  Now we are aware that input() function value will always be of string type, but what to do if we want number to be entered. The solution to this problem is to convert values of input() to numeric type using int() or float() function.
  • 39. Possible chances of error while taking input as numbers 1. Entering float value while converting to int >>> num1=int(input("Enter marks ")) Enter marks 100.5 Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: '100.5‘ 2. Entering of values in words rather than numeric >>> age=int(input("What is your age ")) What is your age Eighteen Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 10: Eighteen'
  • 40. Possible chances of error while taking input as numbers 3. While input for float value must be compatible. For e.g. Example 1 >>> percentage=float(input("Enter percentage ")) Enter percentage 12.5.6 Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not convert string to float: '12.5.6' Example 2 >>> percentage=float(input("Enter percentage ")) Enter percentage 100 percent Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: could not convert string to float: „100 percent'
  • 41. Program 1 Open a new script file and type the following code: num1=int(input("Enter Number 1 ")) num2=int(input("Enter Number 2 ")) num3 = num1 + num2 print("Result =",num3) Save and execute by F5 and observe the result
  • 42. Let us write few programs  WAP to enter length and breadth and calculate area of rectangle  WAP to enter radius of circle and calculate area of circle  WAP to enter Name, marks of 5 subject and calculate total & percentage of student  WAP to enter distance in feet and convert it into inches  WAP to enter value of temperature in Fahrenheit and convert it into Celsius.  WAP to enter radius and height of cylinder and calculate volume of cylinder.
  • 43. Just a minute…  What is the difference between keywords and identifiers  What are literals in Python? How many types of literals in python?  How many types of String in python?  What are the different ways to declare multiline String?  What is the error in following python program: print(“Name is”, name)
  • 44. Just a minute…  Why the following code is giving error? Name="James" Salary=2000 0 Dept="IT" print("Name is ",Name) print(Dept) print("Salary is ",salary)
  • 45. Just a minute…  WAP to obtain temperature in Celsius and convert it into Fahrenheit.  What will be the output of following code: x, y = 6,8 x,y = y, x+2 print(x,y)  What will be the output of following code: x,y = 7,2 x,y,x = x+4, y+6, x+100 print(x,y)