Comprehensive notes Python basics for AI Class 9

Comprehensive notes Python basics for AI Class 9 will talk about the Python basics for Artificial Intelligence, Subject Code 417 of CBSE skill courses. In the previous article we have seen how to install Anaconda and jupyter notebook, creating and accessing the virtual environment, and writing a simple program with jupyter notebook.

Watch this video to understand how to install python:

Follow these links, if you have missed those articles:

Installation of Anaconda

Writing programs in Jupyter Notebook

Comprehensive notes Python basics for AI Class 9

So let’s start this article Comprehensive notes Python basics for AI Class 9 with python statements.

Statements

As we are writing the script of drama, essay or any language-related contents for speech or presentation etc. in languages like English, Hindi, Similarly, the program is also one type of script. So as we are writing sentences, similarly, in programs, we are writing statements.

A program statement is the instruction written in program to execute certain type of code. There are certain number of lines written in the code to execute some specific tasks. These lines are known as statements.

Example, The programmer want to print the product of 5 and 6, then he will write something like this:

print(5 * 6)

So here the python interpreter identifies the print() function and the * operator and display the product of 5 and 6 – 30.

The next section of Comprehensive notes Python basics for AI Class 9 tells about the comments.

Comments

Sometimes we need some statements that are not going to be executed, but some text needed for the programs. These type of text is known as comments. Whatever written in these comments are ignored by the interpreter.

Comments are the statements which are incorporated in the code to give a better understanding of code statements to the user.

There are two types of comments in python.

  1. Single Line
  2. Multi Line

Single Line comment

A single-line comment is used to add some explanatory text in the program for better understanding of the next line. A # sign is used to write a single line comment in the python program. For example,

#A statement to add two numbers
res = 6 + 7
#Print the result
print(res)
Python single comment in Jupyter notebook
Python single comment in Jupyter notebook

Multiline comments

The multiline comments are written in python using triple quotes. You can write number lines starting with triple quotes and end with triple quotes. For example,

'''Write a python program to display the difference between two numbers, the first number should be larger than second number'''
n1=5
n2=2
res=n1 - n2
print(res)
Multiline comments in python - Jupyter notebook
Multiline comments in python – Jupyter notebook

In the next section of Comprehensive notes Python basics for AI Class 9, we will discuss about keywords.

Keywords

Keywords are the reserved words or pre-defined words with a special meaning to the machine by default. So the user cannot use them anywhere else or it cannot be changed or modified in the entire program. They are always case-sensitive.

You have to use the same for the entire program. Click here to see the list of keywords. The next section of Comprehensive notes Python basics for AI Class 9 will talk about the identifiers.

Identifiers

Identifiers are the names declared and used by the programmer. The identifiers are also case-sensitive. Identifiers can be used anywhere and anyway by the user in the program. You cannot use any keyword as an identifier.

Variables

A program contains data like numbers and text. To hold these numbers and text you need some storage. So the variables come into the picture over here. The variables are identifiers declared by the user and named storage location to hold a specific value.

The variable can change the value anywhere in the program. Follow some rules of naming convention while declaring a variable. These rules are:

  1. It must start with an alphabet.
  2. It should not have any space, special characters.
  3. Keywords cannot be used as variable.

In the next section of Comprehensive notes Python basics for AI Class 9 you will learn about datatypes.

Datatypes

In program, you have a choice to use any type of data such as real numbers, numbers with decimals, numbers without decimals, text, etc. These type of data is defined by datatype in Python. The python interprets the type of the variable according to the value stored in the variable. Follow the below-given link to know more about data types.

Python Datatypes

In the next section of Comprehensive notes Python basics for AI Class 9 we will discuss about the input() function.

input() function

The input() function is used to accept values from the user at runtime. This function accepts and returns the text data by default. Therefore, you need to specify the data type if you want to use numbers or any other datatype. This process is known as typecasting. Observe these screenshots code:

python input() function in jupyter notebook
python input() function in jupyter notebook
2
python input() function in jupyter notebook 2
Comprehensive notes Python basics for AI Class 9
Output 1

So in the above output, you have seen that the final output is 58 which is not an addition but python join both numbers and returned 58. To avoid this you need to use typecasting in this manner. Observe the below-given code and understand it!

type casting into int in python
type casting into int in python

Operators

I have written a detailed article on python operators. Follow the below given link for the same.

Python Operators

So here I am concluding this article Python basics for AI Class 9. I hope you understand it very well. If you have any doubt or queries feel free to ask in the comment section.

Thank you for reading this article. Follow the below given link to read more about AI class 9 or similar contents related to Python basics for AI Class 9.

Artificial Intelligence

One thought on “Comprehensive notes Python basics for AI Class 9”

Leave a Reply