Programs are the set of instructions given to a computer to perform a particular task.
Python was developed by Guido Van Rossum.
Python is called a/an interpreted language.
Python is a/an case-sensitive language in terms of its syntax.
In Python, a syntax error is detected by the interpreter at runtime.
Python is a/an platform independent language.
To start Python from the command prompt, use the python command.
Python programs are saved using the .py or .pyw extension.
Python programming can be done in interactive and script modes.
Interactive mode does not save the commands entered by you in the form of a program.
The shortcut key to run Python script is F5.
Python is a dynamically typed language.
Answer
True
Reason — Python is a dynamically typed language because variables do not need to be declared with a specific type. Instead, the type of a variable is determined at runtime based on the value assigned to it.
Alt+R is used to repeat the last typed command in Python shell.
Answer
False
Reason — For repeating or recalling the last command in the Python shell, the correct key is the up arrow key (↑).
Print and print are same in Python.
Answer
False
Reason — In Python, print and Print are not the same because Python is a case-sensitive language.
The sep argument is used with print() method.
Answer
True
Reason — The sep
argument in the print()
function is used to specify a string that separates the objects being printed. The default separator is a space.
Python is a compiled high-level language.
Answer
False
Reason — Python is an interpreted high-level language.
Python is a cross-platform language.
Answer
True
Reason — Python is a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux, etc.
Python is an interpreted language, not a compiled language.
Answer
True
Reason — Python is an interpreted language, not a compiled language. This means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.
Python is a free, open-source and portable language.
Answer
True
Reason — Python is free and open-source, meaning anyone can freely use, distribute, and modify it. It is also highly portable, running on various platforms such as Windows, macOS, Linux, and others.
Python Editor refers to Script mode in Python.
Answer
True
Reason — Python Editor refers to a mode in IDLE where we can write and run Python scripts, also known as Script mode.
Ctrl+Q shortcut key combination is used to exit Python.
Answer
True
Reason — Ctrl+Q shortcut key combination is used to exit Python.
Python was developed by ............... .
- Charles Babbage
- Guido van Rossum
- Tim Berners Lee
- Robert E. Kahn
Answer
Guido van Rossum
Reason — Python was developed by Guido van Rossum.
Which of the following is syntactically correct text?
- "This is great!"
- 'she shouted 'HELLO' loudly'
- "Goodbye'
- "This "course" is good"
Answer
"This is great!"
Reason — The "This is great!"
text uses double quotes (") to properly enclose the entire string. In Python, strings enclosed in either single quotes (') or double quotes (") are valid, but the entire string must be enclosed in the same type of quote. The other options have mismatched quotes, which cause syntax errors in Python.
Python language is ............... .
- Free
- Open Source
- Free and Open Source
- Proprietary
Answer
Free and Open Source
Reason — Python is a free and open-source language.
Identify the correct print() statement:
- print(Hello)
- print("Hello")
- print('Hello")
- print("Hello')
Answer
print("Hello")
Reason — In Python, when using the print()
function, strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct statement is print("Hello")
.
Which of the following is the shortcut key combination for exiting Python shell?
- F5
- Alt+F1
- Ctrl+E
- Ctrl+Q
Answer
Ctrl+Q
Reason — The shortcut key combination for exiting Python shell is Ctrl+Q.
The extension for a Python file is given as:
- .pt
- .pwy
- .py or .pyw
- .yppy
Answer
.py or .pyw
Reason — The extension for a Python file is .py or .pyw.
Python is a/an ............... language.
- Compiled
- Interpreted
- Compiled & Interpreted
- None of these
Answer
Interpreted
Reason — Python is an interpreted language. This means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.
The interactive interpreter of Python is termed as ............... .
- Python shell
- Python Script mode
- Python Editor mode
- Python command line
Answer
Python shell
Reason — The interactive interpreter of Python is termed as Python shell.
The three greater than signs (>>>) are called the Python ............... .
- Cursor
- Command prompt
- Pointer
- Blinking cursor
Answer
Command prompt
Reason — The three greater than signs (>>>) are called the Python command prompt or interactive prompt.
Single-line comments in Python begin with ............... symbol.
- %
- "
- '''
- #
Answer
#
Reason — The # symbol in Python indicates the start of a single-line comment, which extends from the # to the end of the line.
Which of the following codes is correct?
1.
print("Programming is fun")
print("Python")
print("Computer Science")
2.
print ("Programming is fun)
print("Python")
print("Computer Science)
3.
Print("Programming is fun")
print("Python")
print("Computer Science")
4.
Print("Programming is fun")
Print("Python")
Print("Computer Science")
Answer
print("Programming is fun")
print("Python")
print("Computer Science")
Reason — In Python, the print()
function is written in lowercase (print) and strings must be enclosed in matching pairs of either single (') or double quotes ("). Therefore, the correct code would be :
print("Programming is fun")
print("Python")
print("Computer Science")
Python is a case-sensitive language. This means ............... .
- Capital and small letters are same for Python
- Python doesn't care about the case of alphabets
- Python treats capital and small letters as different
- Python automatically capitalizes the small letters
Answer
Python treats capital and small letters as different
Reason — Python is a case-sensitive language. This means that Python differentiates between capital and small alphabets.
............... mode of Python gives instant result of typed statement.
- Interactive mode
- Script mode
- Both Interactive and Script mode
- None of these
Answer
Interactive mode
Reason — Interactive mode of Python gives instant result of typed statement.
Assertion (A): Python is an object-oriented programming language.
Reasoning (R): Using Python, any software can be designed. Everything in Python is an object.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python is an object-oriented programming language, which means it supports the concepts of classes and objects. In Python, everything is treated as an object, including integers, strings, functions, and even modules and packages. Using Python, any software can be designed.
Assertion (A): Python uses an interpreter to convert source code to object code.
Reasoning (R): Python interpreter is a special virtual engine that converts machine code to source code.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is true but R is false.
Explanation
Python uses an interpreter to convert source code to object code. The Python interpreter is a special virtual engine that converts source code (written in Python) to machine code that can be executed by the computer.
Assertion (A): To print the value of a variable, Python uses print() method.
Reasoning (R): print() method displays the content on the system screen or console.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
The print()
function is a built-in function in Python that displays the content on the system screen or console. To print the value of a variable, Python uses the print()
function.
Assertion (A): Python is a cross-platform language.
Reasoning (R): Python code can run on a variety of platforms such as windows, Macintosh and Apple.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python is a cross-platform language because it can run on various operating systems, such as Windows, Macintosh, Apple, Linux etc.
Assertion (A): Python is a dynamically typed language.
Reasoning (R): Python interpreter assigns variables a data type at runtime based on the variable's value at that time.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python is a dynamically typed language because variables do not need to be declared with a specific type. Instead, the type of a variable is determined at runtime based on the value assigned to it.
Assertion (A): Python is the fastest language.
Reasoning (R): Python is an interpreted language.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
A is false but R is true.
Explanation
Python is not considered the fastest programming language as it is slower than many compiled languages such as C or C++ because it is interpreted rather than compiled. Python is an interpreted language, which means that Python code is executed line by line at runtime by an interpreter, without the need for a separate compilation step to machine code.
Assertion (A): Python IDLE or Interpreter provides two modes to work with, create and run the scripts or code.
Reasoning (R): Interactive mode comprises Python prompt '>>>' where you can simply start typing the command and display output, and script window, where you can write Python program in a file and execute it to display output.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python's Integrated Development and Learning Environment (IDLE) or interpreter provides two modes to work with: interactive mode and script mode. Interactive mode comprises the Python prompt '>>>' where we can start typing commands and see the output immediately. In script mode, we can write a Python program in a file and execute it to display the output.
Assertion (A): Python is a general-purpose language, meaning it can be used to create a variety of different programs.
Reasoning (R): Python is used to build websites and software, automate tasks and conduct data analysis.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Answer
Both A and R are true and R is the correct explanation of A.
Explanation
Python is a general-purpose language, meaning it is versatile and can be used to create a variety of programs. Python is an object-oriented language used to build websites and software, automate tasks, and conduct data analysis.
When was Python introduced?
Answer
Python was developed in February 1991.
Who developed Python and which two languages contributed to Python as a programming language?
Answer
Guido Van Rossum is the developer of Python. ABC language and Modula-3 contributed to Python as a programming language.
Python is free and open-source. What do you understand by this feature?
Answer
Python is free and open-source means that it is available to anyone at no cost, and its source code can be freely accessed, modified, and distributed by anyone.
Is Python case-sensitive?
Answer
Yes, Python is a case-sensitive language. This means that Python differentiates between uppercase (capital) and lowercase (small) letters.
What is IDLE?
Answer
IDLE is a simple Integrated Development and Learning Environment that comes with Python. The most important feature of IDLE is that it is a program that allows the user to edit, run, browse and debug a Python program from a single interface.
Differentiate between displaying and printing method in Python.
Answer
Printing in Python refers to using the print()
function to output information to the console. The print()
function takes one or more arguments, converts each argument to a string (if necessary), and displays them as text. On the other hand, displaying can be a more general term that encompasses presenting information or output in various forms, not limited to just text output in the console.
Briefly explain the salient features of Python.
Answer
The salient features of Python are as follows:
- Python is an interpreted, interactive, directly executed language with a pre-compiled code. This means that it is processed at runtime by the interpreter and we need not compile our program before executing it.
- It is a loosely type object-oriented programming language with a few keywords, simple English-like structure and is easy to learn.
- It is a free, open-source and portable language having a large repository of libraries.
- It takes less time to develop as Python programs are typically 3 to 5 times shorter than the equivalent programming languages. This is because of its built-in, high-level data types and its dynamic typing.
- It is extensible/extendable and highly efficient as there is no wastage of time in declaring the types of variables or arguments.
- It supports GUI (Graphical User Interface) and garbage collection (better memory management).
- It is easily compatible with other languages like C, C++, Core Java etc.
- Python is used for both scientific and non-scientific programming.
What do you understand by cross-platform software with respect to Python?
Answer
Python is platform-independent and a cross-platform language because it can run on various operating systems, such as Windows, macOS, Linux etc.
What are the advantages of Python programming language?
Answer
Advantages of Python programming language are:
- Easy to Use — Python is compact, programmer-friendly and very easy to use object oriented language with very simple syntax rules.
- Expressive Language — Python is an expressive language, it takes fewer lines of codes to represent the same syntax.
- Interpreted Language — Python is an interpreted language, not a compiled language. It makes Python an easy-to-debug language and thus suitable for beginners to advanced users.
- Completeness — Python has a rich standard library that provides modules for most types of required functionality like emails, web-pages, databases, GUI development, network connections, etc.
- Cross-platform Language — Python can run equally well on variety of platforms — Windows, Linux/UNIX, Macintosh, supercomputers, smart phones, etc.
- Free and Open Source — Python language is freely available along with its source-code.
- Variety of Usage/Applications — Python has evolved into a powerful, complete and useful language over these years. These days Python is being used in many diverse fields/applications, some of which are Scripting, Web Applications, Game development, Database Applications, System Administrations, Rapid Prototyping, GUI Programs.
In how many different ways can you work in Python?
Answer
We can work in Python in two ways:
- Interactive mode (also called Immediate mode)
- Script mode
What are the advantages/disadvantages of working in Interactive mode in Python?
Answer
Interactive mode is useful for testing code. We can type the commands one by one and get the result of error immediately for each command. Disadvantages of Interactive mode are that it does not save commands in form of a program and also output is sandwiched between commands.
Write some limitations of Python.
Answer
Some limitations of Python programming language are:
- Not the Fastest Language — As Python is an interpreted language so its execution-times are not that fast compared to some compiled languages.
- Lesser Libraries than C, Java, Perl — Library collection of C, Java, Perl is better than Python.
- Not strong on Type-Binding — Python interpreter is not very strong on catching 'Type-Mismatch' issues.
- Not easily convertible — Translating Python programs to other languages is difficult due to its lack of syntax.
What is the difference between Script mode and Interactive mode in Python?
Answer
In script mode, we write a Python program in a file and execute it to display the output and in interactive mode, we use the Python prompt '>>>' to start typing commands and see immediate output.
Write instructions to the Interactive mode for the following:
(a) To display sum of 3, 8.0, 6 * 12
(b) To print sum of 16, 5.0, 44.0
Answer
(a)
>>> 3 + 8.0 + 6 * 12
(b)
>>> print(16 + 5.0 + 44.0)
Write the output of the following:
num1 = 4
num2 = num1 + 1
num1 = 2
print(num1, num2)
Answer
2 5
In the above code, num1
is initially assigned the value 4. Then, num2
is set to num1 + 1
, resulting in num2
being 5. Subsequently, num1
is reassigned the value 2, changing its original value from 4 to 2. When print(num1, num2)
is executed, it displays the current values of num1
and num2
, which are 2 and 5, respectively.
Consider the statements given below and write Python command to display these statements in both Interactive and Script mode.
Python is easy to learn and write.
It allows us to work in two modes: Interactive mode and Script mode.
Interactive mode is also known as Python Shell and Script mode is also known as Python Editor.
It is a platform-independent language.
We find it interesting to work with Python.
Answer
Interactive Mode:
>>> print("Python is easy to learn and write.")
>>> print("It allows us to work in two modes: Interactive mode and Script mode.")
>>> print("Interactive mode is also known as Python Shell and Script mode is also known as Python Editor.")
>>> print("It is a platform-independent language.")
>>> print("We find it interesting to work with Python.")
Script Mode:
print("Python is easy to learn and write.")
print("It allows us to work in two modes: Interactive mode and Script mode.")
print("Interactive mode is also known as Python Shell and Script mode is also known as Python Editor.")
print("It is a platform-independent language.")
print("We find it interesting to work with Python.")
Write a code that prints your full name and your birthday as separate strings.
Answer
full_name = "Jeevika Sharma"
birthday = "January 17, 2000"
print("Full Name:", full_name)
print("Birthday:", birthday)
Full Name: Jeevika Sharma
Birthday: January 17, 2000
Record what happens when the following statements are executed:
(a) print (n = 17)
(b) print (8+9)
(c) print (4.2, "hello", 6-2, "world", 15/2.0)
Answer
(a) It raises TypeError as 'n' is an invalid keyword argument for print()
function.
(b) 17
(c) 4.2 hello 4 world 7.5
Use IDLE to calculate:
(a) 6+4*10
(b) (6+4) *10
Answer
(a) 46
(b) 100
Try the following code on the Python shell and evaluate the output generated:
>>> print (3.14159*7)
>>> print('I am a class XI' + 'student')
>>> print('I', 'am')
>>> print ("class XI student")
>>> print ("I'm", 16, "years old")
Answer
21.99113
I am a class XIstudent
I am
class XI student
I'm 16 years old