0% found this document useful (0 votes)
14 views5 pages

Introduction To Python-1

The document provides an introduction to Python, covering its definition, applications in AI, and key programming concepts such as data types, variables, and identifiers. It includes comparisons between interactive and script modes, as well as between integer and float data types. Additionally, it features an assignment section with questions related to Python programming and its features.

Uploaded by

sahraunak240
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)
14 views5 pages

Introduction To Python-1

The document provides an introduction to Python, covering its definition, applications in AI, and key programming concepts such as data types, variables, and identifiers. It includes comparisons between interactive and script modes, as well as between integer and float data types. Additionally, it features an assignment section with questions related to Python programming and its features.

Uploaded by

sahraunak240
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/ 5

INTRODUCTION TO PYTHON

1)What is a program?

A computer program is a collection of instructions that perform a specific task when executed
by a computer. It is usually written by a computer program in a programming language.

2)What is Python ?

Python is a widely used general-purpose, high-level programming language. It was created


by Guido van Rossum in 1991.

3)Why Python for AI?

4)Name the applications of AI.

5)Differentiate between the following: (any two)

a) Script mode and Interactive mode


Topic Interactive Mode Script Mode
A mode where Python code is executed
A mode where Python code is written
Definition directly, line by line, in a shell
in a file (script) and executed later.
environment.
The entire script is executed after
Code is executed immediately when
Execution being saved and run using the
pressing "Enter."
interpreter.
Useful for quick tests, debugging, or Ideal for writing and executing larger
Use Case
simple calculations. or more complex programs.
Writing a Python file like example.py
Example >>> 5 + 3 (Output: 8) and running it with python
example.py

b) Integer datatype and Float datatype

Topic Integer Datatype Float Datatype

Represents whole numbers, Represents numbers with


Definition both positive and negative, decimal points or scientific
without decimal points. notation.

Range is typically from - Can represent very large or


Range 2147483648 to 2147483647 very small numbers with
for standard integers. floating-point precision.

Example 3.14, -21.9, 0.98333328,


100, -99, 0, 17 15.2963
Values

No fractional part or Can store fractional values or


Precision decimal points.
decimal precision.
Can be written as 1.23e4
Scientific Cannot be written in (meaning 1.23 * 10^4) or -
Notation scientific notation. 2.5E-3 (meaning -2.5 * 10^-
3).

c) Single line and multiline comments


6) Define Identifier. Also list rules for naming the identifiers with examples.

For example-

Var1 , _var1,_1_var,var_1

7) Define the following terms :-

a)Variables- A variable is a named location used to store data in the memory.

For example, x = 42

b)Constants - A constant is a type of variable whose value cannot be changed

c)Data Types- specify the type of data that can be stored inside a variable.For example-

num=24

Here, 24 is integer.So data type is Int.


ASSIGNMENT
1)What would be the output of the following Python code?

a = b = c = "Hello"

print(a)

print(b)

print(c)

a) Hello Hello Hello b) a b c


c) Hello b c d) Error

2)Which of the following is NOT a valid Python identifier?

a) valid_name b) _valid123
c) 123valid d) var_1

3)Which of the following is a valid Python identifier?

a) 3value b) first-name
c) _testVar d) yield

4)What does IDLE stand for?


a) Integrated Development and Launch Environment
b) Integrated Development Environment
c) Interactive Development Language Editor
d) Integrated Debugging and Learning Environment

5)What value is stored in variable y?

x, y, z = "apple", 10, 3.14

a) apple b) 10 c) 3.14 d) None

6) What will be the output of the following Python code?

Website = "xyz.com"

print(Website)

Website = "abc.com"

print(Website)

a) xyz.com b) xyz.com c) abc.com d)None

xyz.com abc.com xyz.com None


7)Who created Python, and in which year was it first released?

a) Guido van Rossum, 1991


b) Linus Torvalds, 1992
c) Dennis Ritchie, 1985
d) James Gosling, 1990

8)Which of the following is TRUE regarding Interactive Mode and Script Mode in
Python?

a) Interactive Mode is ideal for writing and executing larger or more complex programs,
while Script Mode is used for quick tests and simple calculations.
b) Script Mode allows immediate execution of code line by line, whereas Interactive Mode
requires the code to be saved first before execution.
c) In Interactive Mode, code is executed immediately after pressing "Enter", while in Script
Mode, the entire script is executed after being saved and run using the interpreter.
d) Script Mode is not suitable for debugging or testing small pieces of code, while
Interactive Mode is better for running large programs.

9) Which of the following statements about variables in Python is true?

a) A variable in Python is a named location in memory that holds constant data and cannot be
changed.
b) Variables in Python are containers that can hold data, and their values can be changed
during the program's execution.
c) In Python, variables are only used to store integer data types.
d) Variables in Python can only be used to store one type of data, such as strings or numbers.

10) Which of the following statements about identifiers in Python is true?

a) An identifier in Python is used to differentiate entities like classes, functions, and


variables, but it can start with a digit.
b) An identifier in Python is a name given to entities like classes, functions, and variables,
and it must start with a letter or an underscore.
c) An identifier in Python is a reserved word used to define the behavior of the program.
d) An identifier in Python is a name used only for classes and functions, but not for variables

You might also like