0% found this document useful (0 votes)
24 views109 pages

2) Unit 1

Uploaded by

vexifay977
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views109 pages

2) Unit 1

Uploaded by

vexifay977
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 109

Python

Language &
Features
What is Python?
Modes of Instruction
Errors in
Python
1. SYNTAX ERROR
2. RUN TIME ERROR
SYNTAX ERRORS
RUNTIME ERRORS
About Python Program
Types of Comments

1. Single Line Comments

2. Docstring Comments
Identifiers in Python
RULES FOR IDENTIFIERS
KEYWORDS
Various Keywords in
Python
VARIABLES
Chained
Assignment
Operators
Operators in Python
Assignment statements in
Python

1. Basic Assignment statements

2. Augmented Assignment statements


Basic Assignment
Statement
Augmented Assignment
Statement
Contd…
Example:
INDENTATION IN
PYTHON
Example:
Data Types in Python
Data types categorize data for efficient processing
in Python and all programming languages.
They assign specific characteristics to data,
enhancing accuracy and control in operations.
The data type of the data
determines :
 possible values it can be assigned.
 possible operations that can be performed.
(Arithmetic operations can be applied on numeric
data and not strings)
the format in which it is stored in the memory.
 the amount of memory allocated to store the data.
Some of the built-in data types supported
in Python are:-

Number
String
List
Tuple
Set
Dictionary
Contd….
The same variable in Python can refer to data of
different data types at different times.
Thus, variables in Python are not strongly typed,
implying that you don't have to explicitly declare
the data type of a variable when creating it.
Example:
Numbers
There are 3 different categories of Numbers in
Python.
Int
Float
Complex
Int:
Float:
Complex:
List
Sets in Python
Contd…
Tuple
Allows duplicate values:
To find Tuple length:
Dictionary
Example:
Example:
thisdict = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
print(thisdict["brand"])
Input and Output
Statements
Example:
Basics of Python
Programming
Arithmetic Operators
Python Booleans :
Booleans represent one of two
values: True or False.
You can evaluate any expression in Python, and
get one of two answers, True or False.
Print a message based on whether the
condition is True or False:
Evaluate Values and Variables

The bool() function allows you to evaluate any


value, and give you True or False in return.
Evaluate a string and a
number:
Evaluate two variables:
Contd…
Some Values are False
Contd….
if you have an object that is made from a class
with a __len__ function that returns 0 or False:
Functions can Return a
Boolean
You can execute code
based on the Boolean
answer of a function
Print "YES!" if the function returns True,
otherwise print "NO!"
Data Type Conversion
The act of changing an object’s data type is known
as type conversion.
Data Type Conversion
Example:
Identity Operator
Note:
Example:
Contd….
Operator precedence
Contd…
Operator precedence
Contd…
Question
Contd …
(Note: - instead of 82.0, use 32.0 in below written code)
Contd…
For loop example:
If else example:
Python program to calculate the sum of numbers from 1 to a user-
defined positive integer using If else.
Contd….
Output:-
Logical Operator
Contd…
Contd…
Contd…
Syntax for If-else statement:
Contd…
Example:
Problem statement
Contd…
Contd…
Solution:
Problem statement
Contd…
Solution:
Problem statement
Contd…
Solution:
Logical Not
Contd…

You might also like