Python Notes Class X Artificial Intellgence
Python Notes Class X Artificial Intellgence
By creating separate Python virtual environments for each project, a virtual environment is
a tool that aids in maintaining the separation of dependencies needed by various projects.
The majority of Python developers utilise this as one of their most important tools.
Step 2 : As we open the Anaconda prompt, we can see that in the beginning of the prompt
message, the
term (base) is written.
Step 4 : After processing, the prompt will ask if we wish to proceed with installations or not.
Type Y
on it and press Enter.
Introduction to Python
Guido Van Rossum, of Centrum Wiskunde & Informatica, is the inventor of the Python
programming language. The language, which took its name from the 1970s BBC comedy
series “Monty Python’s Flying Circus,” was made available to the general public in 1991. It
can be used to programme in both an object-oriented and procedural manner. Because it
offers so many features, Python is very popular.
Python has few keywords, simple structure and a clearly defined syntax. Python allows
anyone to learn the language quickly. A program written in Python is fairly easy-to-
maintain.
Python has a huge bunch of libraries with plenty of built-in functions to solve a variety of
problems.
Interactive Mode
Python has support for an interactive mode which allows interactive testing and debugging
of snippets of code.
Python can run on a wide variety of operating systems and hardware platforms, and has the
same interface on all platforms.
Extendable
We can add low-level modules to the Python interpreter. These modules enable
programmers to add
to or customize their tools to be more efficient.
Applications of Python
There exist a wide variety of applications when it comes to Python. Some of the
applications are:
1. Application of Python
2. Web and Internet Development
3. Desktop GUI Applications
4. Business Application
5. Software Development
6. Games and 3d Graphics
7. Database Access
Python Basics
Keywords & Identifiers
Some terms in Python have predefined meanings that the computer automatically assigns
to them. These phrases are referred to as keywords. In order to avoid misunderstanding
and unclear results, keywords should only be used in the default manner and cannot be
changed at any point in time. The following list includes a few of the keywords:
Example of Keywords –
False, class, finally, is, return, None, continue, for lambda, try, True, def, from, nonlocal,
while, and, del, global, not, with, as, elif, if, or, yield, assert, else, import, pass, break, except,
in, raise etc.
Variables & Datatypes
Variables
There are a certain rules and regulations we have to follow while writing a variable
1. A number cannot be used as the first character in the variable name. Only a character
or an underscore can be used as the first character.
2. Python variables are case sensitive.
3. Only alpha-numeric characters and underscores are allowed.
4. There are no special characters permitted.
Constants
A constant is a kind of variable that has a fixed value. Constants are like containers that
carry information that cannot be modified later.
AGE = 20
Datatype
In Python, each value has a datatype. Data types are basically classes, and variables are
instances (objects) of these classes, because everything in Python programming is an
object.
Python has a number of different data types. The following are some of the important
datatypes.
1. Numbers
2. Sequences
3. Sets
4. Maps
a. Number Datatype
Numerical Values are stored in the Number data type. There are four categories of number
datatype –
1. Int – Int datatype is used to store the whole number values. Example : x=500
2. Float – Float datatype is used to store decimal number values. Example : x=50.5
3. Complex – Complex numbers are used to store imaginary values. Imaginary values
are denoted with ‘j’ at the end of the number. Example : x=10 + 4j
4. Boolean – Boolean is used to check whether the condition is True or False. Example :
x = 15 > 6 type(x)
b. Sequence Datatype
A sequence is a collection of elements that are ordered and indexed by positive integers. It’s
made up of both mutable and immutable data types. In Python, there are three types of
sequence data types:
d. Mapping
Dictionaries
In Python, Dictionaries are used generally when we have a huge amount of data. A
dictionary is just like any other collection array. A dictionary is a list of strings or numbers
that are not in any particular sequence and can be changed. The keys are used to access
objects in a dictionary. Curly brackets are used to declare a dictionary. Example : d =
{1:’Ajay’,’key’:2}
Operators
Operators are symbolic representations of computation. They are used with operands,
which can be either values or variables. On different data types, the same operators can act
differently. When operators are used on operands, they generate an expression.
• Arithmetic operators
• Assignment operators
• Comparison operators
• Logical operators
• Identity operators
• Membership operators
• Bitwise operators
Arithmetic Operators
+ Addition 20 + 20 40
– Subtraction 30 – 10 20
/ Division 30 / 10 20
// Integer Division 25 // 10 2
% Remainder 25 % 10 5
** Raised to power 3 ** 2 9
Assignment Operator
= x=10 x = 10
+= x += 10 x = x + 10
-= x -= 10 x = x – 10
*= x *= 10 x = x * 10
/= x /= 10 x = x / 10
Comparison Operator
The values are compared using comparison operators or relational operators. Depending
on the criteria, it returns True or False.
20 < 50 False
10 < 40 True
== Equal To 5 == 5 True
5 == 6 False
35 != 35 False
Logical Operator
Logical operators are used to combine the two or more then two conditional statements –
Operator Meaning Expression Result