0% found this document useful (0 votes)
11 views28 pages

Class-9 Python Notes

Python is a high-level, interpreted programming language known for its readability and simplicity, making it a popular choice among developers since its release in 1991. It supports various applications, including web development, data analysis, and artificial intelligence, and is backed by major organizations like Google and Microsoft. While Python offers numerous advantages such as ease of learning and extensive libraries, it also has drawbacks like poor memory efficiency and slower execution speed.

Uploaded by

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

Class-9 Python Notes

Python is a high-level, interpreted programming language known for its readability and simplicity, making it a popular choice among developers since its release in 1991. It supports various applications, including web development, data analysis, and artificial intelligence, and is backed by major organizations like Google and Microsoft. While Python offers numerous advantages such as ease of learning and extensive libraries, it also has drawbacks like poor memory efficiency and slower execution speed.

Uploaded by

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

Introduction to Python

Python is a high-level programming language and is widely being used


among the developers’ community. Python was mainly developed for
emphasis on code readability, and its syntax allows programmers to express
concepts in fewer lines of code. Python is a programming language that lets
developers work quickly and integrate systems more efficiently. It was created
by Guido van Rossum, and released in 1991at Centrum Wiskande Informatika
(CWI) Netherland

its latest version is 3.7.1, we can simply call it as Python3. Python 3.0 was
released in 2008. and is interpreted language i.e it’s not compiled and the
interpreter will check the code line by line.

Applications :
1) GUI based desktop applications(Games, Science)
2) Web frameworks and applications
3) Enterprise and Business applications
4) Operating Systems
5) Language Development
6) Prototyping
Organizations using Python Language :
1) Google(Components of Google spider and Search Engine)
2) Yahoo(Maps)
3) YouTube
4) Mozilla
5) Dropbox
6) Microsoft

Features of Python
1. Simple Syntax

When it comes to programming, understanding the syntax of the language is


very important. The program will not work if it’s not syntactically correct. With
different languages, the ease with which you code, comes with practice.

In Python, the developers of the language wanted to make sure that the
language would be as close to the human language as possible. This was
done while keeping the programming rules in mind and hence the language
has a simple syntax.

2. Easy to Learn
Python being simple to code is one of the main reasons the language has
become popular over time. The simple syntax allows people to work with it
easily.
It allows people who are not familiar with programming to pick up a new
language quickly. It also gives an advantage to developers to code without
having to debug or have errors in the code too often.
3. Free and Open Source

When Guido Van Rossum was developing the language, he was set on the
idea that the language should be available to all. This allowed people from all
around the world to access the language with ease and also help build the
language further.
Python is a free/libre and open-source software (FLOSS), which makes
reading the source code, distributing the software, and making changes to it
quite easy.
4. High-level Language

Python is a high-level programming language, which focuses on making the


code easier for the programmer. High-Level languages are easier to
comprehend and work with.
High-level languages are slower than low-level languages because their syntax
is not understood by the machine. In high-level languages, there comes a step
where you need to convert this code into a code the computer can understand
(low-level code) either during or before runtime.
However, people still prefer high-level languages like Python because of the
ease and simplicity of working with them.
5. Interpreted

To understand how this feature separates Python from other programming


languages, let’s understand the difference between a compiled language and
an interpreted language.In a compiled language, the program is first converted
into binary code so that your computer can understand it.
Only after this first step does your computer execute the code, as depicted in
the flowchart below. In interpreted languages, the step of first converting the
main code into a binary code does not take place. The code is then converted
to machine code during runtime, which makes the language easy to debug and
portable, as seen in the flowchart below.

6. Memory Allocation
Now that we have established how a high-level language and interpreted
language works, let’s look at how the memory allocation in such a language
takes place.
In Python, memory allocation becomes easier because when you assign a
value to a variable, automatic memory allocation takes place during run time.

7. Portable

Portability is one of the major advantages of using Python. Python is free for all
open-source languages and high-level languages which allows you to work on
multiple platforms and operating systems.
You can use python on operating systems such as Linux, UNIX, Windows, Mac
OS X / OS X / macOS, etc.

8. Object-Oriented

When we talk about object-oriented programming, the main goal here is to


focus on the data and functionality and build the program around the object.
Let us look at some of the advantages of object-oriented programming
languages. OOP allows the reusability of codes.
It also works on data redundancy, which allows you to store the data in multiple
memory locations. Data redundancy provides memory backup in case you lose
the memory at one location.
Having OOP, in turn, allows the concept of inheritance, polymorphism, and
encapsulation to come into play.
9. Procedure-oriented

Python is one of the few programming languages that supports both object-
oriented programming as well as Procedural Programming.
This feature allows you to work on the reusable functions that focus on solving
the problem at hand.
You can also use this feature to call the same function in other areas of the
code as well.
10. Classes

Python is an object-oriented programming language that allows the use of


classes.
You can use OOP to create multiple parent and child classes. These classes
follow the class inheritance rules. This allows the parent class to override any
method of the child class. The mechanism also allows the child to call a
method from the parent class.
11. Extensible

Python has a very helpful feature that allows developers who are comfortable
and confident with C/C++/Java code to write code in these languages. This
makes Python extensible as you can extend these languages onto other
programming languages.
Since C and C++ are not interpreted languages, the code is first converted to
machine code and then run on Python.
12. Embeddable

Python also has a feature that allows you to generate codes in other languages
and embed them into python code or vice-versa.
13. Extensive Standard Library

Python is free and open-source, which led people from all around the world to
come up with libraries focusing on various areas.
Over time, there has been a generation of a vast range of libraries, starting
from libraries for documentation, regulation to machine learning, natural
language processing, web scraping, etc.
14. Wide Range of In-Built Functions

Other than the functions that these wide ranges of libraries provide, Python has
a set of extensive inbuilt functions that can be used without accessing any
library.

15. Supports exception handling

When programs are created, a good number of them will have certain
functions, inputs or problems that, when faced, can disrupt the flow of the
program.

These are considered to be exceptions. If they are identified in advance can


prevent the program from either crashing or going into an infinite loop.

Python is one of the few languages that are capable of supporting exception
handling to a great extent which makes it a developer and programmer’s
favorite language.

16. Robust

Python’s ability to work well with exceptions and exception handling, as well as
its ease of use and comprehension has made the error rate in the code reduce.
This makes the language a very reliable and robust language to work with.

17. Advance features


Python has a wide range of other advanced features such as list, dataframes,
dictionary, and generator comprehensions.

18. GUI Programming Support

Now, we have established that Python has a vast range of libraries. One of
their unique libraries is the Graphic User Interface library which developers use
for developing Desktop applications.

Advantages Of Python Over Other Languages


Python is a well-known programming language among tech savvies. In this
section, let’s understand the advantages and applications of Python over
other programming languages with an example. We will explore more
about Python’s features and efficiency.
1. Python is Simple to Learn and Use
The simplicity of the language is the greatest boon. Why?
Let’s take an example. Suppose, you have used a particular language in building
your app. Now, what if the developer who built it leaves the team? You will need
to replace them, right? If the language is hard to learn, or too complex, you will
find it hard to replace the original developer who developed it. Fortunately, this is
not an issue with Python. Python is beginner-friendly and has less
complexity as compared to a language like Java. This generally converts to not
having issues with hiring other developers for your project. Its simplicity is also
the reason many startups like Instagram, Dropbox, and YouTube started with
Python.
2. Perfect for Rapid Deployment
In the age of startups, rapid development is paramount. You just can't wait for
years before launching your application. Technology changes every three to
six months, and so do user preferences. And that’s why Python is often
considered as one of the best languages for rapid deployment.
Let’s see the reasons why.
 Firstly, Python has REPL which stands for read - evaluate, print loop.
This loop enables interactive development where developers can test and
experiment with code snippets quickly. This interactivity fosters a more
iterative development process.
 Secondly, Python’s versatility is unmatched. Python is applicable in
almost all the major domains including web development, data science,
automation, Internet of Things, manufacturing and so much more! You
have the flexibility to use Python for a range of tasks without changing
code to suit the platforms.

3. Python has High-Performance


Python is like a sprinter in coding, proving that not all interpreted languages are
slow. It achieves high performance through clever tricks. One of them is
its smart memory management – Python uses a dedicated space for memory
and a garbage collector to tidy up unused parts, avoiding memory leaks and
keeping things efficient. Then there's PyPy, a dynamic translator that turns
Python code into machine code on the go. This makes Python run faster, putting
it on par with languages known for their speed.
Python's high-performance strength shines, especially in tasks involving lots of
number crunching. Libraries like NumPy and Pandas, written in efficient
languages like C or Fortran, ensure Python handles heavy-duty math
operations.

4. Strong Support for Data Analysis and Scientific Computing


Python is a great helper for data analysis and scientific computing, thanks to
special tools like NumPy, Pandas, and Matplotlib. These tools give
developers the ability to analyze and visualize data effectively.
When you have a lot of data to dig through, Python's Pandas library is a
standout. It provides specific tools designed to manipulate and analyze data.
At the same time, another library NumPy makes the math part easy,
simplifying complex calculations. Together, these tools create a strong setup
for analysts working with data. For scientific computing tasks, Python has
another tool called SciPy. It adds even more useful features, making it handy
for tasks like optimization, signal processing, or dealing with numbers.

5. User-Friendly Built-in Data Types


Python makes dealing with data easy and friendly. Python's data types are
like a helpful friend, ensuring you can handle data without getting tangled in
confusing steps. It's all about making things straightforward and efficient,
making Python a go-to language for managing data with ease.
It has simple structures, like lists, which are like containers for your stuff. With
lists, you can add, remove, or change things hassle-free. Then there
are dictionaries, which work like real dictionaries but for data. You store
information with key-value pairs, making it easy to organize and find what you
need. And if you want a collection of unique items, sets in Python are like a
tidy solution, keeping everything distinct without any repeats.

6. Python Needs Less Coding


Python keeps things simple with its easy-to-understand syntax. It allows
developers to express complex ideas with fewer lines of code compared to
some other languages like Java. For instance, what might take 7 lines in C+
+ only needs 3 lines in Python. As a result, Python greatly reduces
boilerplate code and speeds up development time. Fewer lines of code
also convert to benefits like less usage of space and less debugging.
For Example: Suppose you are working on some data analysis project, and
you require some complicated math to do some operations on data. With
Python’s simple way of writing code and pre-build libraries, you can express
complex math formulas in just a few lines, making it much easier to
understand without writing complex lines of code.
7. Python Has OS Portability
Python's OS portability is like a tech superhero that talks to any computer.
Imagine you create a cool program on one computer, and guess what?
Python makes it work smoothly on other computers too! Whether
it's Windows, macOS, or Linux – Python's got it co vered, no stress. And it
doesn't stop there – Python works with all kinds of computers. Unlike C++
where you need to make some modifications to run C++ code depending
on the operating system you intend to use. So, when you code with
Python, it's like your program becomes universal code, easily running on
different computers without any problems.
Python's adaptability not only makes coding simpler but also gives developers
the confidence that their project will effortlessly work on different operating
systems.

8. Python is Flexible in Deployment


Python’s ability to deploy applications flexibly is like having a versatile tool for
sending programs to different places. Whether it's on servers, desktops, or even
in the cloud, Python makes the process smooth and efficient. Imagine a team
wanting to launch a web application. Python’s adaptability becomes clear
as Python supports various deployment ways. From traditional servers to
modern cloud platforms, Python, allows developers to choose the best
development method for their projects. But it doesn't stop there-Python also
works well with other technologies like Docker, making deployment even more
consistent. It's like packing your application in a special bundle so that it works
the same way, no matter where it goes.

9. Support from Renowned Corporate Sponsors


Python gets a big thumbs-up from some major players in the tech domain,
like Google, Microsoft, and Facebook. These corporate giants aren't just
cheering from the sidelines - they are actively making it better.
For Example: Imagine you are a developer picking a programming language
for your next big project. Knowing Google, Microsoft, and Facebook are
putting their weight behind Python gives you confidence. It's like having the
support of the pros, ensuring that Python isn't just a trend but a reliable
choice for the long run. Having these industry giants on Python’s side adds
an extra layer of trust. Developers worldwide can rely on Python, not just for
its amazing features, but also because it's backed by the expertise and
resources of these major corporate sponsors.

10. Hundreds of Community Driven Python Libraries and


Frameworks
Python is like a treasure chest for developers, filled with a set of community-
made Python libraries and Python frameworks. Think of these libraries as
organized tool sets, each designed for specific coding challenges. Over 30
years, Python devs worldwide have built hundreds of these libraries to make
things easier for future developers. These libraries cover everything from web
development to data analysis. These libraries act as ready-made solutions,
allowing developers to focus on their projects without reinventing the wheel.
Frameworks are another powerful aspect of Python. Languages like C++ or
C# or even Java cannot match the quality and community-backed
Python frameworks. For example, consider Django and Flask. They
simplify web application development by offering pre-built components and
clear structures.
This collaborative support system ensures that developers have a lot of
resources at their fingertips. It makes Python the go-to language for projects
of all sizes and

Disadvantages of Python
1. Poor Memory Efficiency

To make it simple for the developer, Python needs a lot of memory space; this
can be a tad problematic if you want to develop apps where you need to
optimize memory.

2. Slow Speed
After the high memory usage, it’s lack of speed is one of the biggest
disadvantages of Python.

As it executes the code one line at a time, the speed of execution often is
hampered. Where speed is important for the project, Python cannot be used
for coding.
3. Database Access

Though it is easy to program with Python, the database access layer is


underdeveloped compared to other technologies like ODBC.

For enterprise apps, it’s imperative that there is hassle-free interaction of


complicated legacy data, and hence it is not an ideal language for such apps.
4. Weak in Mobile Computing

Python is used for backed programming; due its high memory usage and slow
speed, it is generally not used for frontend programming or mobile app
development.
5. Runtime Errors

The data types of variables in Python can change suddenly, as it is a


dynamically typed language. A variable holding a string may contain an integer
later, and this can lead to runtime errors.
Role of python in Artificial Intelligence
Python offers the least code among others and is in fact 1/5 the
number compared to other OOP languages. No wonder it is one
of the most popular in the market today.

 Python has Prebuilt Libraries like Numpy for scientific


computation, Scipy for advanced computing and Pybrain for
machine learning (Python Machine Learning) making it one
of the best languages For AI.
 Python developers around the world provide comprehensive
support and assistance via forums and tutorials making the
job of the coder easier than any other popular languages.
 Python is platform Independent and is hence one of the
most flexible and popular choiceS for use across different
platforms and technologies with the least tweaks in basic
coding.
 Python is the most flexible of all others with options to
choose between OOPs approach and scripting. You can also
use IDE itself to check for most codes and is a boon for
developers struggling with different algorithms.

Some Common Libraries in Python


1. NumPy
NumPy is the short name for Numerical Python, which is a Python library
predominantly used for technical and scientific computing. Its array-oriented
computing capabilities make it an essential tool for fields such as linear algebra,
statistical analysis, and machine learning.
2. Pandas
Pandas is an open-source data manipulation library for Python. It is built on
top of the NumPy library. It introduces two primary data structures Series and
DataFrame. Series is a one-dimensional labelled data whereas DataFrame
is a two-dimensional labelled data resuming a table..
3. Matplotlib
Matplotlib is a data visualization library that allows developers to create
static animated and interactive animations in Python. The graphs and plots it
produces are extensively used for data visualization.
4. TensorFlow
Tensorflow an open-source Python library for machine learning and
artificial intelligence. It is particularly used for training and inference of deep
neural networks.
5. PyTorch
PyTorch is an open-source library designed for tasks such as computer
vision and natural language processing (NLP) .
6. Scikit-learn
Scikit-learn is a machine-learning library that provides tools for data mining
and analysis. It includes lots of machine learning algorithms for different tasks.
7. Requests
The request library allows you to send HTTP requests extremely easily. It is
widely used for interacting with the web APIs.
8. Keras
Keras is a high-level neural network API that is used for building artificial
neural networks. It is modular and helps us to construct neural network
models layer by layer

10. metplotlib
Plotly is a Python library helpful in the creation of interactive and visually
appealing plots and charts for your data.
Key Features:
11. Pygame
Pygame is a Python library that is used for developing video games or
multimedia applications.
12. spaCy
spaCy is a Python library that is predominantly used for natural language
processing (NLP). It is very fast, efficient, and production-ready hence suitable
for many NLP tasks.
13. SciPy
SciPy is a Python library used for scientific and technical computing. It is
built on top of NumPy so it has additional functionalities for various
scientific computing tasks.
14. PyBrain
PyBrain is a library in Python that is developed to provide tools for artificial
intelligence, machine learning, and neural network research.
15. PyPy
It is a dynamic translator used in python for program execution
Operators in Python
Operators are the signs and symbols used to perform different types
of calculations , comparison and combination of values / variable and
expression in python programs . the values or variables that we use
with the operators are known as operand . when operators ,
keywords , values , variables , function etc. are combined to form
expression . operators are the building blocks of expressions which
can be used to manipulate the data.
Example 1 :- 15 + 28 Here 15 and 28 are operands and + is
operator
Example 1 :- a+b-c Here a,b,c are operands and + - are operator
Python provides 7 main operators:-
1) Arithmetic Operators
2) Relational Operators
3) Logical Operators
4) Assignment Operators
5) Augmented Operators ( Short hand Operators )
6) Identity Operators ( in , is not)
7) Membership Operator ( in , not in)
Arithmetic Operators
Python arithmetic operators perform basic mathematical operations
on numeric data, such as addition, subtraction, multiplication,
division, modulus, exponentiation, and floor division. Python
arithmetic operators can be applied to various data types, including
integers, floating-point numbers, and complex numbers. Python
supports automatic type conversion when working with mixed numeric
data types in calculations.

There are 7 arithmetic operators in Python. The lists are given


below:
Operato Description Syntax &
r Example

Addition + Addition: adds two x+y


Operator operands Ex-10+15=25
12+13= 25

Subtraction – Subtraction: x–y


Operator subtracts two Ex-150-100=50
operands 53-10=43

Division / Division (float): x/y


Operator divides the first Ex- 9/4 = 2.25
operand by the Ex-15/3 = 5
second

Floor Division // Division (floor): x // y


Operator divides the first Ex- 21//6 = 3
operand by the 28//4 = 7
second

Modulus % Modulus: returns the x%y


Operator remainder when the 9 % 2= 1
first operand is 8%4=0
divided by the
second

Exponentiatio ** Power (Exponent): x ** y


n Operator Returns first raised 2**3=2*2*2=8
to power second
It follows right to left

Precedence of Arithmetic Operators in Python


Let us see the precedence and associativity of Python Arithmetic
operators.
Associativit
Operator Description y

** Exponentiation Operator right-to-left

Modulos, Multiplication, Division, and


%, *, /, // left-to-right
Floor Division

+, – Addition and Subtraction operators left-to-right


print (2**2**3) Ans 256 print(3**2**2) Ans-81 print(2**3**2) Ans-
512
print(4**2*3 + 24/3*2-5+18-4) Ans-73.0
print(7 * 2 + 8 -4**2 + 8/2 - 6 + 15//4) Ans - 7.0

Relational Operators
Relational operators in python are used to establish relationship
between two entities, typically involving comparisons such as
equality, inequality, greater than, and less than .These operators
evaluate the comparison and return a Boolean value, which is either
True or False. They enable the comparison of values, facilitating
critical functionalities such as conditional execution, data filtering,
validation, and the efficient implementation of algorithms. By allowing
the development of complex logical conditions, relational operators
enhance both the functionality and interactivity
> Greater Then >= Greater Then equals
< Less Then <= Less Then Equals
== Equality != inequality

a == b
Python a+b == b+a Result
= Equal to: True if both
Equality – True
= operands are equal
Operators a*b != a/b Result -
True

Inequality != Not equal to: True if a != b


Operators operands are not equal (a+5 != a+10) =
True
(a>b != b>a) false

a>b
Greater than: True if the a*b > a/b Result
Greater left operand is greater True
>
than Sign than the right a*b*c < a+b+c
Result False

a<b
Less than: True if the left a+b < a*b = Result
Less than operand is less than the
< True
Sign right a-500 < a+500
Result-True

Greater Greater than or equal to: a>= b


than or > True if left operand is 10>=10 Result-True
Equal to = greater than or equal to 3**2 >=2**3 Result
Sign the right = false

Logical Operators
Python logical operators are used to combine conditional
statements, allowing you to perform operations based on multiple
conditions. These Python operators, alongside arithmetic operators,
are special symbols used to carry out computations on values and
variables. In this article, we will discuss logical operators in Python
definition and also look at some Python logical operators programs,
to completely grasp the concept.
Logical Operators in Python
In Python, Logical operators are used on conditional statements
(either True or False). They perform Logical AND, Logical
OR, and Logical NOT operations.
Operator Description Syntax Example

Returns True if
both the (10>5) and (10<10)
and x and y
operands are True and False = False
true

or Returns True if x or y (a+100 > a+200) or


either of the (a+b==b+a)
operands is False or True = True
Operator Description Syntax Example

true

Returns True if not(x>7 and x<5)


not the operand is not x
false not(True and False) =True

Assignment Operators Assignment Operators in Python are used


to assign values to variables or vales of the variables to the
variables . variables are written in the left hand side and value or
expressions are written in the right side .

Operato
r Description Syntax

Assign the value of the right side x=y+z


= of the expression to the left side s=10+20+30=60
operand p=(a*b) + (a-b)

Augmented Operators Augmented Operators in Python are used


to reassign values to variables or vales of the variables to the
variables . They are combination of arithmetic and assignment
operator.

Operato
r Description Syntax

Add AND: Add right-side operand a+=b a=a+b


+= with left-side operand and then Ex n=5 n+=5 then
assign to left operand n=10
Operato
r Description Syntax

Subtract AND: Subtract right a-=b a=a-b


-= operand from left operand and then Ex n=20 n-=5 then
assign to left operand n-15

Multiply AND: Multiply right operand a*=b a=a*b


*= with left operand and then assign to Ex k=4 k*=2 then
left operand k=8

Divide AND: Divide left operand a/=b a=a/b


/= with right operand and then assign Ex-p=32 p/=4 then
to left operand p=8

Modulus AND: Takes modulus using


a%=b a=a%b
%= left and right operands and assign
r=12 r%=2 then r=0
the result to left operand

Divide(floor) AND: Divide left Ex a//-=b a=a//b


operand with right operand and T=13
//=
then assign the value(floor) to left t/=4 then t=3
operand

Assigns power , Calculate the result Ex-a=2 a**=3


**=
and restores the result Then a=8

Membership Operators Membership operators are used to find


out if a value or variable is a part of a sequence. In Python, there are
two membership operators: “in” and “not in.”

1. The “in” operator: The “in” operator checks if a value or


variable is present in a sequence or not. It returns True if the value
or variable is found in the sequence, and False otherwise.
List = [1,2,3,4,5]
Print (3 in List) Result-true
Print (9 in List) Result-false
Text1=”SAMBALPUR”
Print(“S” in Text) Result = true
Print(“SAM” in Text1) Result =False)
Text2=”SOME BIG CITIES”
Print(“BIG” in Text2) Result=-True

2. The “not in” operator: The “not in” operator checks if a value
or variable is not present in a sequence. It returns True if the
value or variable is not found in the sequence, and False
otherwise.

List = [1,2,3,4,5]
Print (3 not in List) Result-False
Print (9 not in List) Result-True

Text1=”SAMBALPUR”
Print(“SAM” not in Text) Result = False
Print(“SOM” not in Text1) Result = True
Text2=”SOME BIG CITIES”
Print(“BIG” not in Text2)Result= Ture
Print(“DID” not in Text2) Result=-true

Use cases for membership operators: Membership operators are


commonly used to check if an element is present in a list or tuple.
They are also used to search for characters or substrings in a string.
They are particularly useful when you want to check if a certain value
or variable is present in a collection before performing an action on
it.

Identity Operators

When comparing two objects’ locations in memory, identity operators


are employed. In Python, there are two identity operators: “is” and
“is not.

1. The “is” operator: The “is” operator checks if two objects


refer to the same memory location or not. It returns True if both
objects refer to the same memory location, and False
otherwise.Exampls:-
String1=”RAJAN”
String2=”RAJAN”
Print((String1 is String2) Result=True
String1=”RAJAN”
String2=”RAMAN”
Print((String1 is String2) Result=False
List1=[1,2,3,4]
List2=[1,2,3,4]
Print(list1 is list2] Result=True
List3=[1,2,3,]
List4=[4,5,6]
Print(list3 is list4] Result=False

2.The “is not” operator: The “is not” operator checks if two
objects do not refer to the same memory location. It returns True if
both objects do not refer to the same memory location, and False
otherwise.

Examples-

String1=”RAJAN”
String2=”RAJAN”
Print((String1 is not String2) Result=False
String1=”RAJAN”
String2=”RAMAN”
Print((String1 is not String2) Result=True
List1=[1,2,3,4]
List2=[1,2,3,4]
Print(list1 is list2] Result=False
List3=[1,2,3,]
List4=[4,5,6]
Print(list3 is not list4] Result=True

Use cases for identity operators: Identity operators are commonly


used to compare two objects and check if they refer to the same
memory location. They are useful when you want to determine if two
objects are actually the same object in memory.

Operator Precedence used in Python-PEMDAS

It is the sequence or the order in which operators are executed on


after the next in an expression , the operators with higher
precedence gets executed first followed by the operators with lower
precedence, Like we use BODMAS in math here we use PEMDAS
principe / hierarchy.
Operator Precedence Operator
1 ()
2 ** (exponent )
3 * / % //
4 +-
5 <= < > >=
6 == (Equality) != Inequality
7 = %= , /= //= , = , -= += , *= **=
8 Not and or (logical operator)

All the operators follows left to right pretense , but ** only


supports right to lef
Print() and input() used in Python

Print() function is used to generate the results or print the


different results of the programs on the screen / monitor. We can
print he value of the variables or directly the text message using
double quotes .
Print(“Good students in class”)
Print(“Name is “,n)

input() function is used to enter the values to the variables at the


time of program execution . we can use type conversion while
entering values to the variable in different types of data functions
like
Example-1 n=str(input(“enter the student name “))
Example-2 r=int(input(“enter the roll number “))
Example-3 p=float(input(“enter the percentage “))

Token used in Python


Keywords:-
Python Keywords are some predefined and reserved words in
Python that have special meanings. Keywords are used to define the
syntax of the coding. The keyword cannot be used as an identifier,
function, or variable name. All the keywords in Python are written in
lowercase except True and False. There are 35/36 keywords in
Python 3.11. we cannot alter / redefine the keywords . They form
the vocabulary of a language
Rules for Keywords in Python
 Python keywords cannot be used as identifiers.
 All the keywords in Python should be in lowercase except True
and False.
Example – for , while , def , if , else , print , input , int , str , float etc.

Identifiers :-
Identifier is a user-defined name given to a variable, function,
class, module, etc. The identifier is a combination of character digits
and an underscore. They are case-sensitive i.e., ‘num’ and ‘Num’
and ‘NUM’ are three different identifiers in python. It is a good
programming practice to give meaningful names to identifiers to
make the code understandable. They forms the building blocks of a
programs.
Rules for Naming Python Identifiers
 It cannot be a reserved python keyword.
 It should not contain white space.
 It can be a combination of A-Z, a-z, 0-9, or underscore.
 It should start with an alphabet character or an underscore ( _ ).
 It should not contain any special character other than an
underscore ( _ )
Example-n sn r , std_name etc
Literals :-
Literals are the fixed and predefined values that do not change
during the time of program execution , some time they are also
known as constant . when we need a same / common values in a
variables which is same for different object then we use literals. Like
pin_code , school_ code etc
In python we different types of literals
Indentation
Indentation is the space between the margin and block of code that
we write with condition or loop or functions in python program .
indentation is indicated with a colon sign
Example-1
If n:100:
Print(We are good”)

Example-2
For a in range(1,6):
Print(We are Fine”)

Strings Literal
Strings are one of the most common data value types you will work
with in Python, and there are many ways to format strings, and they
cannot used in any mathematical calculation in python programs .
the values . To store string values python uses str data type. A string
can be of any length.
Example – n=”sambalpur” m=’Hirakud’ a=’’’Raman’’’
Integer Literals
Fixed and predefined values in form of whole number which does not
change during the time of program execution. these values can be
used in different types of mathematical calculation. To store integer
values we use int data type. We can store integer values upto any
extend (no limit) . They may be negative or positive Ex-12 ,-24 , 56 ,
-234 etc
Floating Literals
Fixed and predefined values in form of decimal number which does
not change during the time of program execution. these values can
be used in different types of mathematical calculation. To store
decimal values we use float data type. We can store float values upto
any extend (no limit) . They may be negative or positive Ex-9.45 , -
9.75 etc
Boolean Literals
Fixed and predefined values in form of true or false which does not
change during the time of program execution. these values can be
used in checking condition in python program , It may evaluates the
result true or false . Ex- True or False
Null Literals
It is special literal with null (nothing / no value) It does mean zero or
false or empty . It is represented by none.
Type Conversion in Python
It means converting the data from one type to another type so that
they are more compitable in performing different types of
calculations in python programs. Python provides different types of
inbuilt methods used to convert the data. Python read all the data in
text or string from when we enter any type numbers (whole number /
decimal number) then we need to convert them to use them in
mathematical calculations .Like int () , float() , str()
Example-1 n = str(input(“enter ant student name “))
Example-2 r = int(input(“Enter the roll number “))
Example-3 p=float(“Enter the percentage of marks”))
>>> print (float(12)) Result = 12.0
>>>print(int(7.25)) Result = 7
>>>print(str(23)) Result = “23”
>>>print(int(True)) Result=1
>>>print(int(False)) Result=0
To print the data type of the values/objects we can use type
functoion
>>>print(type(15)) Result=int
>>>print(type(9.25)) Result= float
>>>print(type(“raman”)) Result=str
>>>print(type(True) Result=bool
Variable :-
Variable are the memory location that hold that value stored by the
use . . If required we can change the values of the variable after the
program execution. A variable has two part
Name – It the variable name (follows identifier rules) , in programs
we use variable names to access the values stored by the user.
Value – It is the value which user stores in variable .It may store
values of different types like int. floats , String , Boolean ( bool ).
Values in variables store in three methods
Method-1 Assigning different values to different variable in different
line
a=25
b=35
n=”Sambalpur”
Method-2 Assigning different values to different variable in same
line(using semicolon)
>> n=25;m=45;r=12
Method-3 Assigning different values to same variable in same
line(using semicolon)
>> a=b=c=15; here a,b,c has been stored same value 15
to a,b,c

Comment’s used in Python :-


Comments are the non executable parts in a python program , they
are optional means not compulsory . we can add / use comments any
where in the program . It describe / narrtes the aim or purpose of the
programs
There are two types of comments
Single Line comment – This is used to add a comment a line of
single line or one line it must starts with # sign , closing is not
compulsory.
Example - # to find the selling price of product.
Multiple Line Comments- It is used to write the comment of two or
more lines , It must starts with three asterisk signs and ends with
same three asterisk signs .
Example- *** to find the sum
To find the product***
Statements in Python :-
Simple Statement – It is used to line store a single value to a single
variable in one line
Example – s x+y
Multiline Statement – it used to write a single statement in different
lines . to assign continuation we use slash sign (\ forward slash )
12+34-128\
54-71*5 \
10-120
Multiple Statement :- it is used to store(calculate) different values to
different variable in different lines . for this we use ;(semicolon sign)
Ex:- a=b*2 ; b=18/2
Script and Interactive mode in Python :-
Interactive Mode :- In script mode we write a program code of
maximum one line . we use python prompt (>>>) to type the python
code in interactive mode . This mode is widely used to test a code
accuracy and performance . the program code of interactive mode
cannot be stored in computer memory for future use because in this
mode we use RAM/Buffer memory. It produce or give instant result of
the code as soon as we press enter key after tying the code. Here
use the program code with print() function. We cant edit the program
code of interactive mode.
Example :
>>> print(10+20) result =30
>>>print(“Good” + “Day” Result =”GoodDay”
>>>Print((15>10) Result=false
Script Mode :- This mode is widely used in python programs . We
can type any number of lines of programming code in this mode. To
type the program code of script mode we use python editor . we
need to save with a file name the program of script mode
permanently in the computer memory so, that it can used in future
purpose. If required we can edit / modify of script mode . We need to
run / execute (F5) the program of script mode in order to generate
the result or output.

Data types in Python :-


Data types indicates the type of values one can store stored in a
variable . we can store different types of values in variable like int ,
float , str and bool . it is very important task of the user to choose the
most suitable / appropriate data for the variable .
Data type in python

Numbers Sequence sets maps

string dictionary
int
list stores in key
float
tuple & value
complex

String :-
Strings are one of the most common data value types you will work with in Python, the
values of the string is always stored within double quotes or single quotes , it may contain
alphabets , digits , or any special sign or symbols and there are many ways to format
strings, the characters in a string are always accessed / processed it’s index positions . the
index position of the 1st character in a string always starts with zero (o). when we store
numbers in string then they cannot used in any mathematical calculation in python
programs . To store string values python uses str data type. A string can be of any length.
Example –
n=”sambalpur” m=’Hirakud’ a=’’’Raman’’’ x=”””DANGER”””
m="SAMBALPUR" n="SAMBALPUR"
print(n[2]) Result-M print(n==m) Result-True
list:-
 List is a sequence data type used to store a set of data elements .
 A list is an ordered and indexed data type where elements are stored and
accessed in index position.
 Index position of the 1 st elements are always stored starts with 0 (zero)
 The elements is a list are always stored in square brackets . [ ]
 A list is a heterogeneous data type where we can store data of mixed data
type.
 List is mutable means we can add or remove elements is list.
 We can store repeated or redundant elements in a list .
 We can create / define list within another list called nested list.
 List provides maximum functions for it’s operation so it is slow and
consumes more memory space.
 To define/create list in python we use list() function.
Example :
list1=[14,18,43,62,12]
Print(list1[2] Result=43 (3 rd element)
Print(list1[1] + list1[3]) Result = 18+62=80
list2=[“RAMAN”,”KIRAN”,22,33,7,25,8.50] Heterogeneous list
list3=[11,22,33,44,22,66,77,33,99]
tuple:-
 tuple is a sequence data type used to store a set of data elements .
 A tuple is an ordered and indexed data type where elements are stored
and accessed in index position.
 Index position of the 1 st elements are always stored starts with 0 (zero)
 The elements is a tuple are always stored in round brackets . ( )
 A tuple is a heterogeneous data type where we can store data of mixed
data type in a tuple.
 We can create/define one tuple within another tuple called nested list.
 tuple is immutable means we cannot add or remove elements once a tuple
is created and stored with some elements.
 We can store repeated or redundant elements in a tuple.
 We can create / define tuple within another tuple called nested tuple
 tuple provides less functions for it’s operation so it is fast and consumes
less memory space.
 To define/create tuple in python we use tup() function.
Example :
tup1=(14,18,43,62,12)
Print(tup1(2)) Result=43 (3 rd element)
Print(1(1tup) + tup1(3)) Result = 18+62=80
Tup3=(“RAMAN”,”KIRAN”,22,33,7,25,8.50) Heterogeneous tuple
Tup4=(11,22,33,44,22,66,77,33,99) repeated elements are taken only once
set:-
 List is a non sequence data type used to store a set of data elements .
 A list is an unordered and unindexed data type where elements are stored
and accessed without index position.
 The elements is a list are always stored in curly brackets . { }
 A set is a heterogeneous data type where we can store data of mixed data
type in a set.
 We cannot create one set within another set.
 The elements of a set are processed in ascending by default.
 The elements in a set are unique / distinct / atomic We cannot store
repeated or redundant elements in a tuple.
 sets provides very less functions for it’s operation so it is vey fast and
consumes less memory space.
 To can define/create set in python we use set() function.
Example :
set1={14,18,43,62,12}
Print(set1)
set3={“RAMAN”,”KIRAN”,22,33,7,25,8.50}Heterogeneous set
set4={11,22,33,44,22,66,77,33,99}
dictionary:-
 Dictionary a non sequence data type used to store a set of data elements.
 A dictionary is an unordered and unindexed data type where elements are
stored and accessed without index position.
 The elements is a list are always stored in curly brackets . { }
 The elements in a dictionary are used in pair (map) where 1 st part is called
key and second part is called data.
 The key and data must be separated by colon sigh :
 Key part in a dictionary is must be atomic/unique but if required we can
store duplicate values.
 We cannot create one dictionary within another dictionary. vides very less
functions for it’s operation so it is vey fast and consumes less memory
space.
 To can define/create dictionary in python we use dict() function.
Example :
dict1={14:”RANMAN”,18:”GOPLA”,43:”SHYAM”,62:”AMIT”}
Print(dict1)
Dict2={1:”RAMA”, 2:”SANJAY” : 3:”GOPAL” , 4:”RAMA” , 5:”DAD”}

REVIIOSN PRCTICE QUESTIONS:- (PYTHON)


1) What do mean by python language ? Who developed it and when ?
2) Explain the important features of python language ?
3) Explain some advantages of python language ?
4) Explain some disadvantages of python language ?
5) Explain the role of python in Artificial Intelligence ?
6) Write the difference between script and interactive mode used in python ?
7) Explain different types of statements used in python ?
8) Explain the types of remarks / comments used in python ?
9) Explain the four basic data types used in python ?
10) Define String with suitable example ?
11) Write some important features / properties of list ?
12) Write some important features / properties of tuple?
13) Write some important features / properties of set ?
14) Write some important features / properties of dictionary ?
15) Explain the character set used in python ?
16) Write the difference between ASCII & UNICODE ?
17) Define keywords with some example ?
18) Define identifiers with some example ?
19) Define Literals ? explain it’s types ?
20) Define indentation used in python with examples ?
21) What do you mean by separators ? Explain in details ?
22) Explain arithmetic operators with suitable examples ?
23) Explain relational operators with suitable examples ?
24) Explain logical operators with suitable examples ?
25) Explain augmented / shorthand operators with suitable examples ?
26) Explain membership operators with suitable examples ?
27) Explain membership operators with suitable examples ?
28) Explain operators precedence with suitable examples ?
29) Explain any five important libraries used in python ?
30) What do you mean by white space characters ? Give some example ?

REVIIOSN PRCTICE QUESTIONS:- (ARTIFICAIL INTELLIGENCE)


1) What do you mean by Artificial Intelligence ? Write it’s impotence ?
2) Explain the important features of AI ?
3) Explain the important advantages of AI ?
4) Explain the important disadvantages of AI ?
5) Explain the turing test with a diagram ?
6) Define AI winter in the history in AI ?
7) Define AI Boom in the history in AI ?
8) Explain the importance of year 2000 in AI ?
9) Write the difference between human intelligence and artificial Intelligence ?
10) What do you mean by AI Bias ? Explain the main reasons AI Bias ?
11) Explain how mitigate / minimize / control AI Bias ?
12) Explain the types of bias in AI ?
13) Explain the Ethical consideration of AI ?
14) Explain the ole of AI in the field of Agriculture ?
15) Explain the ole of AI in the field of Industrial ?
16) Explain the ole of AI in the field of Medical / Healthcare ?
17) Explain the ole of AI in the field of Finance and banking ?
18) Explain the ole of AI in the field of Military and Defense ?
19) Explain the ole of AI in the field of Social Media and Surveillance ?
20) Explain ? concept of AR and VR in AI ?

You might also like