Quantcast
Channel: Learn CBSE
Viewing all articles
Browse latest Browse all 10507

Advanced Python Class 10 Notes

$
0
0

These AI Class 10 Notes Chapter 3 Advanced Python Class 10 Notes simplify complex AI concepts for easy understanding.

Class 10 AI Advanced Python Notes

Jupyter Notebook Class 10 Notes

A Jupyter Notebook is a powerful tool widely used in the field of data science, research, and education. It provides an interactive computing environment that allows you to create and share documents containing live code, equations, visualisations, and narrative text.

Jupyter Notebooks support various programming languages, but it is most commonly associated with Python. Working with Jupyter Notebook, virtual environment is one of the most important tools that used by Python developers.

Introduction to Virtual Environment

A virtual environment is a self-contained directory that encapsulates a specific Python interpreter and its associated libraries. It allows you to create an isolated environment for your Python projects, preventing conflicts between dependencies and ensuring that each project has its own set of libraries and packages.

Advanced Python Class 10 Notes

Installing Jupyter Using Anaconda Class 10 Notes

By creating separate Python virtual environments for each project

1. To install Python virtual environment – JUPYTER Notebook using ANACONDA, type the link: https://www.anaconda.com/products/individual
2. Click on Download
3. Begin the installation process.
4. Getting through the License-Agreement

Advanced Python Class 10 Notes 1

5. Select Installation Type: Select Just Me if you want the software to be used by a single user

Advanced Python Class 10 Notes 2

6. Choose Installation Location.
7. Click on ‘Install’ button.
8. Getting through the Installation Process.
9. Finishing the installation.

Advanced Python Class 10 Notes 3

Once the installation is done, you can start using Anaconda.

Open Anaconda from the Start menu or by double click on the Anaconda icon on your desktop (if you have the icon). Anaconda Navigator will open.
From the Anaconda Navigator – click on Launch button JUPYTER Notebook.

Advanced Python Class 10 Notes 4

The Jupyter notebook will open in the default browser.

Advanced Python Class 10 Notes 5

From the New, select Console.

Advanced Python Class 10 Notes 6

Getting Familiar With Jupyter Notebook
Let’s get familiar with the components of Jupyter Notebook

Advanced Python Class 10 Notes 7

I. The Notebook Dashboard: The Notebook dashboard has two tabs.
(a) Files – All the programs that are saved earlier can be visualised under this section. The extension of these files is .ipynb.
(b) Running – All notebooks that are opened presently can be seen under this tab.

Advanced Python Class 10 Notes

II. Notebook Kernel: The programs that we save on the notebook gets run with the help of an in-built interpreter. Kernel executes the code and shows the result.
The window of the Jupyter notebook has the following parts:

Advanced Python Class 10 Notes 8

Introduction To Python Class 10 Notes

  • Python is a versatile and high-level programming language known for its readability and simplicity. It is created by Guido van Rossum.
  • Python supports multiple programming paradigms, including Procedural, Object-Oriented, and Functional Programming. It has a comprehensive standard library and a vast ecosystem of third-party packages.
  • Its syntax promotes clean and concise code, contributing to increased productivity.

Features of Python

Here are some key features of the Python programming language:
Readability: Python’s syntax is designed to be clear and readable, promoting a more straightforward and maintainable codebase.

Easy to Learn and Use: Python’s simplicity and readability make it an ideal choice for beginners. It has a shallow learning curve, allowing developers to quickly grasp the basics and start coding.

Expressive Language: Python allows developers to express concepts in fewer lines of code than other languages like C++ or Java.

Interpreted Language: Python is an interpreted language, which means that code can be executed directly without the need for compilation.

Dynamic Typing: Python uses dynamic typing, allowing developers to create flexible and adaptable code.

Large Standard Library: Python comes with a comprehensive standard library that includes modules and packages for various purposes, such as web development, data manipulation, networking, and more.

Community Support: Python has a large and active community of developers. This results in a wealth of resources, tutorials, and third-party libraries that can be easily accessed, contributing to problem-solving and collaborative development.

Cross-Platform Compatibility: Python is platform-independent, meaning that Python code can run on various operating systems without modification.

Advanced Python Class 10 Notes

Object-Oriented Programming Python supports Object-Oriented programming, allowing developers to create and use classes and objects, promoting modularity and code reuse.

Integration Capabilities: Python can be easily integrated with other languages like C and C++, enabling developers to use existing code and libraries.

Databases: Python provides interfaces to many commercial and open-source databases, making it a suitable choice for database applications.

Scalability: Python is scalable, making it applicable for small scripts as well as large projects.

Python Applications

Here, we are specifying application areas where Python can be applied.

  • Web applications We can use Python to develop web applications. It provides libraries to handle internet protocols such as HTML and XML, JSON, Email processing, request, beautifulSoup, Feedparser, etc.
  • Desktop GUI Applications The GUI stands for Graphical User Interface, which provides a smooth interaction to any application. Python provides a Tk GUI library to develop a user interface.
  • Software Development Python is useful for the software development process. It works as a support language and can be used to build control and management, testing, etc.
  • Audio or Video-based Applications Python is flexible to perform multiple tasks and can be used to create multimedia applications. Some multimedia applications which are made by using Python are TimPlayer, Cplay, etc.
  • Enterprise Applications Python can be used to create applications that can be used within an Enterprise or an Organization. Some real-time applications are OpenERP, Tryton, etc.
  • Image Processing Application Python contains many libraries that are used to work with the image. The image can be manipulated according to our requirements.

Python Basics Class 10 Notes

Python as a programming language was introduced in class 9. Let us now do a quick recap of some important concepts and syntax necessary for writing a program.

Python Character Set

Character set is a set of valid characters that a language can recognise. A character represents any digit, alphabet and special symbol. The character used in a Python source program belongs to unicode standard.
Python supports the following character set.
Alphabets – A to Z (uppercase), a to z (lowercase)
Digits – 0 to 9
Advanced Python Class 10 Notes 9
Other Characters Python can process any of the ASCII and unicode characters as data or as literals

Identifiers

The identifier is a sequence of characters taken from Python character set.
Identifiers are used to give the name to data items like variables, objects, classes, functions, arrays, etc., to specify their names.

The rules in Python for identifiers are

  1. Only alphabets, digits and underscores are permitted.
  2. Identifier name cannot start with a digit.
  3. Keywords cannot be used as identifier.
  4. Uppercase and lowercase letters are distinct because Python is case sensitive language.
  5. Special characters are not allowed.

e.g. Name, name_1, FirstName etc.

Advanced Python Class 10 Notes

Keywords

Keywords are predefined reserved words by the programming language that have some special or predefined meanings. These are reserved for special purpose and must not be used as identifier names. Some commonly used keywords in Python, which are listed below:

Advanced Python Class 10 Notes 10

Operators

Operators perform a specific task/computation when applied on variable or some other objects in an expression (known as operands). Operators are used in programs to operate on data and variables.
There are two types of operators as follows:

(i) Unary Operators

Those operators that work on single operand to form an expression are known as unary operators.
Following are some unary operators:

Advanced Python Class 10 Notes 11

(ii) Binary Operators

Operators that work upon two operands are known as binary operators.
There are various types of binary operators in Python as follows.
(a) Arithmetic operators These operators are used to do arithmetic operations. These operators are

Advanced Python Class 10 Notes 12

(b) Logical operators These operators are used to make a decision on two conditions. Logical operators are typically used with boolean values and what they return is also a boolean value. These operators are

Advanced Python Class 10 Notes 13

(c) Relational operators Relational operators compare two operands to one another. These operators are

Advanced Python Class 10 Notes 14

(d) Assignment operators Assignment operators are used to assign the value of an expression to a variable. These operators are

Advanced Python Class 10 Notes 15

(e) Bitwise operators Bitwise operators work on bits and perform bit by bit operation. These operators are

Advanced Python Class 10 Notes 16

(f) Shift operators These operators are used to shift value left or right. These operators are

Advanced Python Class 10 Notes 17

(g) Identity operators These operators are

Advanced Python Class 10 Notes 18

(h) Membership operators These operators are

Advanced Python Class 10 Notes 19

Expressions

An expression is a combination of operators, constants and variables as per rule of the language. Any part in a program which can have a value, is an expression. It will have operands and operators together to produce a value.

Advanced Python Class 10 Notes 20

Statements

A statement is a logical instruction, which Python interpreter can read and execute. In Python, it could be an expression or assignment statement. The assignment statement is fundamental to Python.
Advanced Python Class 10 Notes 21
when expression will be evaluated, statement or group of statements executed.

Comments

Comments are non-executable statements that are ignored by the interpreter or compiler and are not executed by the computer.
Comments are written to explain what each block of the program is doing.
There are two types of comments used in programs as follows
(a) Single line comment A single line comment starts with symbol.
e.g. Here is define the function of addition
(b) Multi-line comment A multi-line comment starts with a “‘symbol and ends with”.
e.g. x = 20 “Here we initialise the value of variable x as 20 “‘

Advanced Python Class 10 Notes

Indentation

Indentation indicates the relationship between various statements and thus allow us to get a better picture of the overall organisation and structure of the solution given in the program. It improves the readability of the program.
Advanced Python Class 10 Notes 22
This is block with all its statements same indentation.

Variables Class 10 Notes

Variable is a container object that stores a meaningful value that can be used throughout the program.
Each variable has a specific type, which determines the size and layout of the variable’s memory, the range of values that can be stored within that memory and the set of operations that can be applied to the variable.
A variable can be created anywhere in Python program.
Advanced Python Class 10 Notes 23

Above is an assignment statements which used to assign values to variables.

Dynamic Typing Class 10 Notes

Python is a dynamically type language. It does not know about the type of the variable until the code is run, so declaration is not used. It stores that value at some memory location and then binds that variable name to that memory container. We have assigned a value to variable.

>>> a = 10

But to find the type of this variable, use the type () module Syntax
type (variable_name)
To find the type of above variable, we use
Advanced Python Class 10 Notes 24
Input and Output in Python Class 10 Notes

Input/Output or I/O is the communication between information processing system (such as a computer) and the outside world, possibly a human or another information processing system.
Inputs are the data received by the user, and outputs are the data sent to user. In almost every computer program, the user has to input some data that will be stored in computer’s memory and then subsequently processed. And finally, there is need to output the results of the computations. The output can be displayed on the computer screen.

Input Statement
Python has an input() function which lets you ask a user for some text input.
input( ) function first takes the input from the user and then evaluates the expression, which means Python automatically identifies wifether user entered a string or number or list.

If the input provided is not correct, then either syntax error or exception is raised by Python.
Advanced Python Class 10 Notes 25

Output Statement
To output your data to the screen, use the print () function. print() function gives output an entire (complete) line and then goes to next line for subsequent output. To print more than one item on a single line, comma (.) may be used.

Advanced Python Class 10 Notes 26

Data Types Class 10 Notes

Data types are the classification or categorisation of data items. It represents the kind of value that tells what operations can be performed on a particular data. The following are the standard or built-in data types in Python:

Advanced Python Class 10 Notes 27

Numeric

The numeric data type in Python represents the data that has a numeric value. A numeric value can be an integer, a floating number, or even a complex number. Numeric data type is further classified into three categories.

  • Integers This value is represented by int class. It contains positive or negative whole numbers (without fractions or decimals).
  • Float This value is represented by the float class. It is a real number with a floating-point representation. It is specified by a decimal point. Optionally, the character e or E followed by a positive or negative integer may be appended to specify scientific notation.
  • Complex Numbers A complex number is represented by a complex class. It is specified as (real part) + (imaginary part)j. For example -2+3 j

Advanced Python Class 10 Notes

Dictionary

A dictionary is a key-value pair set arranged in any order. It stores a specific value for each key, like an associative array or a hash table. Value is any Python object, while the key can hold any primitive data type.
The comma ( , ) and the curly braces are used to separate the items in the dictionary.

Boolean
Data type with one of the two built-in values, True or False is known as booléan data type. Boolean objects (True or False) are denoted by the class bool.

Set
It is iterable, mutable(can change after creation), and has remarkable components. The elements of a set have no set order.

Sequence
The sequence data type is the ordered collection of similar or different Python data types. Sequences allow storing of multiple values in an organised and efficient manner.
There are several sequence types in Python –

  • String : The sequence of characters in the quotation marks can be used to describe the string. A string can be defined using single, double, or triple quotes.
  • List : Lists in Python can contain data of different types. Elements of lists are separated with comma (.) and enclosed inside square bracket [].
  • Tuple : Tuples, like lists, also contain a collection of items from various data types. A parenthetical space () separates the tuple’s components from one another.

Control Structure Class 10 Notes

A control structure is a programming language construct which affects the flow of the execution of program.
Various types of control structure are described below

Advanced Python Class 10 Notes 28

Sequence Statements
Sequence statement refer to the instructions that are executed in the sequence in which they are written in the program. When a program is run, the CPU begins execution, executes some number of statements and then terminates at the end.
For example

Advanced Python Class 10 Notes 29

Output
A program which adds two integers
Enter first integer : 5
Enter second integer: 11
Sum is : 16
Selection Statements
These statements allow a program to execute a statement or a set of statements depending upon a given condition. These statements are also called conditional statements or decision statements.
Python provides three types of selection statements are described below:

1. If statement

The if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not.

Advanced Python Class 10 Notes 30

Output
x is greater

2. if-else statement

This statement also tests a conditional expression. If the condition is true, the entire block of statements following the if block and it will be executed.
Otherwise, the entire block of statements following the else block and it will be executed.

Advanced Python Class 10 Notes 31

Output
we are in else part because x is not greater

Advanced Python Class 10 Notes

3. if-elif-else statement

Sometimes, we need to execute different statement to perform in different conditions. It requires the evaluation of several conditions.
First of all, the first condition is evaluated, if it is true then respective statements are processed. Otherwise, the next condition is evaluated to process another say of statements. This process is continued for several times.

Advanced Python Class 10 Notes 32

Expression is tested from the top towards the downside. As soon as the true condition is found, the associated set of statement is executed.
x=55

Advanced Python Class 10 Notes 33

Output
Divisible by 5

4. Nested if statement

Nested means if statement or if-else statements are placed in the statement block of if statement or else statement.

Advanced Python Class 10 Notes 34

Output
result =15

The nested if can have one of the following four forms:
(i) if nested inside both, if part and else part

Advanced Python Class 10 Notes 35

(ii) if nested inside if part

Advanced Python Class 10 Notes 36

(iii) if nested inside else part

Advanced Python Class 10 Notes 37

(iv) One if inside another if statements

Advanced Python Class 10 Notes 38

range( ) Function

The range( ) function is used to generate a sequence of numbers overtime. At its simplest, it accepts an integer and returns a range object (a type of iterable).

The range ( ) function has two forms as follows:
(i) range (stop)
stop number of integers to generate, starting from zero. e.g. range (5) = [0,1,2,3,4]

(ii) range ([start,] stop [,step])

  • start starting number of the sequence.
  • stop generate numbers upto, but not including this number.
  • step difference betweèn each number in the sequence.

Advanced Python Class 10 Notes

Iterative Statements

Iterative statements or loops enable a program with a cyclic flow of logic. Each statement which is written under the scope of a looping statement gets executed the number of times the iteration/looping continues for. There are two basic types of looping statements available in Python, they are as follows.

1. while loop

A while loop tests for its ending condition before executing the statements enclosed in the loop body even the first time.
So, if the ending condition is met when the while loop beings, the lines of instructions its contains will never be carried out. This loop is also known as Entry control loop.
Advanced Python Class 10 Notes 39
A while loop continues iteration cycle till its loop condition is evaluated as true. If the loop-condition is false for the first time iteration, then loop will not execute even once.

Advanced Python Class 10 Notes 40

Output
Enter a natural number : 10
Sum is : 55

2. for loop

The for statement encloses one or more statements that form the body of the loop, the statements in the loop repeat continuously a certain number of times.
This loop is also an entry control loop, as condition is checked before entering into the scope of the loop.

Advanced Python Class 10 Notes 41

Output
A
B
A
B
A
B
A
B

Python Packages Class 10 Notes

Python has a rich ecosystem of libraries and packages that extend its functionality for various purposes. Here are some widely used Python libraries and packages:

  • NumPy It provides support for large, multi-dimensional arrays and matrices, along with mathematical functions to operate on these arrays. Usage Data science, machine learning, scientific computing.
  • Pandas It offers data structures like DataFrame for efficient data cleaning, exploration, and analysis. Usage Data analysis, data cleaning, data manipulation.
  • Matplotlib Comprehensive 2D plotting library. It allows the creation of static, animated, and interactive visualizations in Python.

Usage Data visualization, plotting graphs.
Scikit-learn Machine learning library built on NumPy, SciPy, and Matplotlib. It provides simple tools for data mining and data analysis.

Usage Machine learning, data mining,

  • Beautiful Soup Library for pulling data out of HTML and XML files. It provides Pythonic idioms for iterating, searching, and modifying the parse tree. Usage Web scraping.
  • Django High-level web framework for building web applications quickly. It follows the model-view-controller (MVC) architectural pattern. Usage Web development.
  • Flask Lightweight web framework. It simplifies web application development by providing tools and libraries needed.

Usage Web development.

  • NLTK (Natural Language ToolKit) Library for working with human language data. It provides easy-to-use interfaces for tasks such as classification, tokenization, stemming, tagging, parsing, and more.
  • Usage Natural Language Processing (NLP), text mining.
  • OpenCV (Open Source Computer Vision) Library for computer vision and machine learning. It provides tools for image and video analysis.
  • Usage Computer vision, image and video processing.

Advanced Python Class 10 Notes

Glossary :

  • Jupyter Notebook It is a powerful tool widely used in the field of data science, research, and education Jupyter Notebooks support various programming languages, but it is most commonly associated with Python.
  • Virtual Environment It is a self-contained directory that encapsulates a specific Python interpreter and its associated libraries.
  • Package It is a collection of Python modules organised in a directory hierarchy.
  • Keywords They are reserved words that have special meanings and cannot be used as identifiers.
  • Identifiers They are names used to identify variables, functions, classes, modules, or other objects in the code.
  • Conditional statement it allows you to control the flow of program based on certain conditions.
  • Loops They are used to repeatedly execute a block of code until a specified condition is met.

The post Advanced Python Class 10 Notes appeared first on Learn CBSE.


Viewing all articles
Browse latest Browse all 10507

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>