[go: up one dir, main page]

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

Resource_20250121141100_unit-5_python-notes

The document covers key concepts in Python for Class IX Artificial Intelligence, including homework questions and answers related to Python programming. Topics include the modes of coding, comments, control structures, identifiers, keywords, operators, data types, mutable vs immutable types, lists, and the difference between appending and extending lists. It serves as a foundational guide for students learning Python in the context of AI development.

Uploaded by

info.artcraving
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)
11 views3 pages

Resource_20250121141100_unit-5_python-notes

The document covers key concepts in Python for Class IX Artificial Intelligence, including homework questions and answers related to Python programming. Topics include the modes of coding, comments, control structures, identifiers, keywords, operators, data types, mutable vs immutable types, lists, and the difference between appending and extending lists. It serves as a foundational guide for students learning Python in the context of AI development.

Uploaded by

info.artcraving
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
You are on page 1/ 3

Class IX Artificial Intelligence

Unit-5 Introduction to Python

HOME WORK QUESTION (To be solved in the notebook)


1. Why is Python the first choice of AI developers?
2. What is the difference between an Algorithm and flow chart?
3. What is the difference between a=10 and a==10?
4. Differentiate between the function of the “+” operator when used with integer and string
values.
5. What is the difference between / and // in Python?

Answer the following:

1. What are the different modes for coding in python?


Ans. The different modes in Python are:
Script mode is where you write your code in a .py file and then run it with the python
command. This is the most common way that people use Python because it lets you write
and save your code so that you can use it again later. Script mode produces output that can
be saved and reused.
Interactive mode is where you type your code into the Python interpreter directly. This is
useful for trying out small snippets of code, or for testing things out as you’re writing them.
Interactive mode produces output that is displayed on the screen and then disappears.

2. What are comments in python? List down the various types of comments.
Ans A comment is text that doesn't affect the outcome of a code, it is just a piece of text to let
someone know what you have done in a program or what is being done in a block of code.
In Python, we use the hash (#) symbol to start writing a comment.
Single-Line Comments in Python starts with the hash symbol (#) with no whitespaces and lasts
till the end of the line.
Multi-Line Comments in Python starts with the triple quotes (“““) and ends with triple
quotes(”””)

3. What are the different types of control structures in python?


Ans. Different types of control structures are used to govern the flow of the control in a
program.
1. Sequential statements: These statements are executed sequentially in a program.
2. Conditional statements: These statements are used to transfer program control to a
specific location depending on the outcome of condition ex: IF, IF-ELSE
3. Iterative Statements: These statements are used to execute the set of statements till
the condition is true. ex: FOR, WHILE
4. What are identifiers? Explain the rules for naming an identifier.
Ans In programming languages, identifiers are names used to identify a variable, function, or
other entities in a program. The rules for naming an identifier in Python are as follows:
• The name should begin with an uppercase or a lowercase alphabet or an underscore sign
(_). This may be followed by any combination of characters a–z, A–Z, 0–9 or underscore (_).
Thus, an identifier cannot start with a digit.
• It can be of any length. (However, it is preferred to keep it short and meaningful).
• It should not be a keyword or reserved word given in Table 5.1.
• We cannot use special symbols like !, @, #, $, %, etc., in identifiers.

5. Differentiate between Keywords and Identifiers.


Ans : Keywords are reserved words carrying special meaning and purpose to the language
compiler/interpreter. For example, if, elif, etc. are keywords.

Identifiers are user defined names for different parts of the program like variables,
objects, classes, functions, etc. Identifiers are not reserved. They can have letters, digits
and underscore. They must begin with either a letter or underscore. For example, _chk,
chess, trail, etc.

6. What are operators ? What is their function? Give examples of some unary and binary
operators.
Ans. Operators are tokens that trigger some computation/action when applied to
variables and other objects in an expression.

Unary plus (+), Unary minus (-), Bitwise complement (~), Logical negation (not) are a few
examples of unary operators.

Examples of binary operators are Addition (+), Subtraction (-), Multiplication (*), Division
(/).

7. What are data types? How are they important?

Ans . Data types are used to identify the type of data a memory location can hold and the
associated operations of handling it. The data that we deal with in our programs can be of
many types like character, integer, real number, string, boolean, etc. Hence programming
languages including Python provide ways and facilities to handle all these different types
of data through data types.

The data types define the capabilities to handle a specific type of data such as memory
space it allocates to hold a certain type of data and the range of values supported for a
given data type, etc.
8. What is the difference between a mutable data type and an immutable data type?
Ans. Mutable data types are those that can be modified after their creation. It is suitable for
collections of items where frequent updates are needed Elements can be added, removed,
or changed. Examples: List, Dictionary, Set.
Immutable data types data types are those that cannot be modified after their creation.
Elements cannot be changed once set. Any operation that appears to modify an immutable
object will create a new object. Examples: Numeric (int, float), String, Tuple.

9. Discuss the utility and significance of Lists in Python, briefly.

Ans. Python lists are containers that can store an ordered list of values of same or
different data types together in a single variable.
 The fact that elements of a list need not be homogeneous makes them highly
adaptable and powerful data structure in Python.
 Lists provide fast access to its elements using index numbers.
 Python lists are mutable which makes them memory efficient.
 They serve as the basic building blocks for programs that process large amounts of
data

10. What is the difference between appending a list and extending a list?

Appending a list Extending a list

For appending to a list, append() function


For extending a list, extend() function is used.
is used.

The extend() function can add multiple


The append() function can add a single
elements from a list supplied to it as
element to the end of a list.
argument.

After extend() the length of the list will


After append(), the length of the list will
increase by the length of the list given as
increase by 1 element only.
argument to extend()

You might also like