0% found this document useful (0 votes)
6 views36 pages

Part-B Unit 3 Python Programming

The document provides an overview of Python programming for Class XI students, covering key concepts such as data types, control statements, and libraries like NumPy and Pandas. It introduces Python's features, including its high-level nature and ease of use, and explains fundamental programming elements like tokens, keywords, and operators. Additionally, it discusses CSV files and the importance of libraries in simplifying development tasks.

Uploaded by

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

Part-B Unit 3 Python Programming

The document provides an overview of Python programming for Class XI students, covering key concepts such as data types, control statements, and libraries like NumPy and Pandas. It introduces Python's features, including its high-level nature and ease of use, and explains fundamental programming elements like tokens, keywords, and operators. Additionally, it discusses CSV files and the importance of libraries in simplifying development tasks.

Uploaded by

Savitri Devi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DAV Centenary Public School

Vaishali Nagar, Jaipur-21

Artificial Intelligence (AI-843)


Class XI
Part-B
(Unit 3: Python Programming )
Key concepts:
• Basics of python programming language
• Understanding of character sets, tokens,
modes, operators and data types
• Control Statements
• CSV Files
• Libraries – NumPy, Pandas, Scikit-learn
Introduction to Python
• Python is a general-purpose, high level
programming language. It was created by
Guido van Rossum, and released in 1991.
• Python got its name from a BBC comedy series
“Monty Python’s Flying Circus”
Features of Python
• High Level language
• Interpreted Language
• Free and Open Source
• Platform Independent (Cross-Platform) – runs
virtually in every platform if a compatible python
interpreter is installed.
• Easy to use and learn – simple syntax similar to
human language.
• Variety of Python Editors – Python IDLE,
PyCharm, Anaconda, Spyder
• Python can process all characters of ASCII and
UNICODE.
• Widely used in many different domains and
industries.
Python Editors
• There are various editors and Integrated
Development Environments (IDEs) that you
can use to work with Python. Some popular
options are PyCharm, Spyder, Jupyter
Notebook, IDLE etc.
Getting Started with Python Programs
• Python program consists of Tokens. It is the
smallest unit of a program that the interpreter or
compiler recognizes.
• Tokens consist of keywords, identifiers, literals,
operators, and punctuators. They serve as the
building blocks of Python code, forming the
syntactic structure that the interpreter parses and
executes. During lexical analysis, the Python
interpreter breaks down the source code into
tokens, facilitating subsequent parsing and
interpretation processes.
Keywords
• Reserved words used for special purpose. List
of keywords are given below.
Identifier
• An identifier is a name used to identify a
variable, function, class, module or other
object. Generally, keywords (list given above)
are not used as variables. Identifiers cannot
start with digit and also it can’t contain any
special characters except underscore.
Literals:
• Literals are the raw data values that are
explicitly specified in a program.

• Different types of Literals in Python are


– String Literal
– Numeric Literal (Numbers)
– Boolean Literal (True & False),
– Special Literal (None)
– Literal Collections.
Operators
• Operators are symbols or keywords that
perform operations on operands to produce a
result. Python supports a wide range of
operators:
– Arithmetic operators (+, -, *, /, %)
– Relational operators (==, !=, , <=, >=)
– Assignment operators (=, +=, -=)
– Logical operators (and, or, not)
– Bitwise operators (&, |, ^, <>)
– Identity operators (is, is not)
– Membership operators (in, not in)
Punctuators
Common punctuators in Python include:

: () [] {} , ? | ~ !

; . ` '‘ "" / \ & @


Tokens in the above program are given below

• Keyword - import
• Identifier - num , root (Here it can be said as variables also)
• Literal - 625
• Operator - =
• Punctuator - “ “ , ( ).
Data Types
• Data types are the classification or
categorization of data items. It represents the
kind of value that tells what operations can be
performed on a particular data. Python
supports Dynamic Typing. A variable pointing
to a value of certain data type can be made to
point to a value/object of another data type.
This is called Dynamic Typing. The following
are the standard or built-in data types in
Python:
Data Type Description
Accepting values from the user
• The input() function retrieves text from the
user by prompting them with a string
argument.

• For instance:
name = input ("What is your name?")
Write a program to read name and marks of a student
and display the total mark.
Control flow statements in Python
• Till now, the programs you've created have
followed a basic, step-by-step progression,
where each statement executes in sequence,
every time. However, there are many practical
programs where we have to selectively
execute specific sections of the code or iterate
over parts of the program. This capability is
achieved through selective statements and
looping statements.
Selection Statement
• The if/ if..else statement evaluates test expression
and the statements written below will execute if the
condition is true otherwise the statements below
else will get executed. Indentation is used to
separate the blocks.
Looping Statements

Looping statements in programming languages


allow you to execute a block of code
repeatedly. In Python, there are mainly two
types of looping statements: for loop and
while loop.
For loop
• For loop iterates through a portion of a program
based on a sequence, which is an ordered collection
of items. The “for” keyword is used to start the loop.
• The loop variable takes on each value in the
specified sequence (e.g., list, string, range).
• The colon (:) at the end of the for statement
indicates the start of the loop body. The statements
within the loop body are executed for each iteration.
• Indentation is used to define the scope of the loop
body. All statements indented under the for
statement are considered part of the loop.
• It is advisable to utilize a for loop when the exact
number of iterations is known in advance
• The for loop iterates over each item in the
sequence until it reaches the end of the
sequence or until the loop is terminated using
a break statement. It's a powerful construct
for iterating over collections of data and
performing operations on each item.
Write a program to display even numbers and their squares
between 100 and 110.
Write a program to read a string. Split the string into list of
words and display each word.
Write a simple program to display the values stored in
dictionary
UNDERSTANDING CSV file
(Comma Separated Values)
• CSV files are delimited files that store tabular data
(data stored in rows and columns).
• It looks similar to spread sheets, but internally it is
stored in a different format.
• In csv file, values are separated by comma. Data
Sets used in AI programming are easily saved in
csv format. Each line in a csv file is a data record.
Each record consists of more than one
fields(columns).
• The csv module of Python provides functionality
to read and write tabular data in CSV format
Write a Program to open a csv file [Link] and
display its details
INTRODUCING LIBRARIES
• A library in Python typically refers to a collection of reusable
modules or functions that provide specific functionality.
Libraries are designed to be used in various projects to simplify
development by providing pre-written code for common tasks.
Concept of libraries are very easy to understand.
Some of the Libraries used in Python

• Numpy
• Pandas
• Maths
• Scipy
• Scikit-learn (SKLearn)
DAV Centenary Public School
Vaishali Nagar, Jaipur-21

Artificial Intelligence (AI-843)


Class XI
Part-B
(Unit 3: Python Programming )

You might also like