Programming and Problem Solving through Python

Introduction to Python Question & Answer



Question : 1
What is the difference between a keyword and an identifier?


Answer :

Every language has keywords and identifiers, which are only understood by its compiler. Keywords are predefined reserved words, which possess special meaning. An identifier is a unique name given to a particular variable, function or label of class in the program.



Question : 2
What are literals in Python? How many types of Literals allowed in Python?


Answer :

Literals: Python comes with some built-in objects. Some are used so often that Python has a quick way to make these objects, called literals.

The literals include the string, Unicode string, integer, float, long, list, tuple and dictionary types.



Question : 3
What factors guide the choice of identifiers in program?


Answer :

(i) An identifier must start with a letter or underscore followed by any number of digits and/or letters.

(ii) No reserved word or standard identifier should be used.

(iii) No special character (Other than underscore) should be included in the identifier.



Question : 4
What are tokens in Python? How many types of tokens allowed in Python?


Answer :

Tokens are the smallest unit of the program. There are following tokens in Python:

  •  Reserved words or Keywords
  •  Identifiers
  •  Literals
  •  Operators
  •  Punctuators


Question : 5
What is the role of indentation in Python?


Answer :

Indentation plays a very important role in Python. Python uses indentation to create blocks of code. Statements at same indentation level are part of same block/suit. You cannot unnecessarily indent a statement; python will raise an error for that.



Question : 6
What are data types? What are Python built in core data types?


Answer :

Every value in Python has a datatype. Since everything is an object in Python programming, data types are actually classes and variables are instance (object) of these classes. There are various data types in Python. Some of the important types are listed below.

(i) Numbers

(ii) String

(iii) List

(iv) Tuple

(v) Dictionary



Question : 7
Which data types of Python handle Numbers?


Answer :

It is cleared by name that Number data types are used to store numeric value in Python. The Numbers in Python have following core data types:

(i) Integers

a. Integers (signed)

b. Booleans

(ii) Floating-Point Numbers

(iii) Complex Numbers



Question : 8
What do you understand by term immutable?


Answer :

Immutable types are those data types that can never change their value in place. In Python the following types are immutable:

(i) integers

(ii) floating-point numbers

(iii) Booleans

(iv) Strings

(v) Tuples



Question : 9
What are mutable and immutable types in Python? List both of them.


Answer :

They are as follows:

  •  Lists
  •  Dictionaries
  •  Sets

Immutable types are those data types that can never change their value in place. In Python the following types are immutable:

  •  integers
  •  floating-point numbers
  •  Booleans
  •  Strings
  •  Tuples


Question : 10

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.



Question : 11

What are some limitations of Python programming language?



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 easily convertible — Translating Python programs to other languages is difficult due to its lack of syntax.

Not strong on Type-Binding — Python interpreter is not very strong on catching 'Type-Mismatch' issues.



Question : 12

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



Question : 13

What are 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.



Question : 14

What are the advantages/disadvantages of working in script mode in Python?



Answer :

Script mode is useful for creating programs and then run the programs later and get the complete output. It is not suitable for testing code.




Question : 15

How are keywords different from identifiers ?



Answer :

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.



Question : 16

How are floating constants represented in Python ? Give examples to support your answer.



Answer :

Floating constants are represented in Python in two forms — Fractional Form and Exponent form. Examples:


Fractional Form — 2.0, 17.5, -13.0, -0.00625

Exponent form — 152E05, 1.52E07, 0.152E08, -0.172E-3



Question : 17

How are string-literals represented and implemented in Python ?



Answer :

A string-literal is represented as a sequence of characters surrounded by quotes (single, double or triple quotes). String-literals in Python are implemented using Unicode.



Question : 18

What are operators ? What is their function ? Give examples of some unary and binary operators.



Answer :

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 (/).



Question : 19

What is an expression and a statement ?



Answer :

What is an expression and a statemenAn expression is any legal combination of symbols that represents a value. For example, 2.9, a + 5, (3 + 5) / 4.

A statement is a programming instruction that does something i.e. some action takes place. For example:

print("Hello")

a = 15

b = a - 10t ?



Question : 20

What all components can a Python program contain ?



Answer :

A Python program can contain various components like expressions, statements, comments, functions, blocks and indentation.



Question : 21

What do you understand by block/code block/suite in Python ?



Answer :

A block/code block/suite is a group of statements that are part of another statement. For example:

if b > 5:
    print("Value of 'b' is less than 5.")
    print("Thank you.")




Question : 22

What are variables ? How are they important for a program ?



Answer :

Variables are named labels whose values can be used and processed during program run. Variables are important for a program because they enable a program to process different sets of data.



Question : 23

What do you understand by undefined variable in Python ?



Answer :

In Python, a variable is not created until some value is assigned to it. A variable is created when a value is assigned to it for the first time. If we try to use a variable before assigning a value to it then it will result in an undefined variable. For example:


print(x)   #This statement will cause an error for undefined variable x
x = 20
print(x)

The first line of the above code snippet will cause an undefined variable error as we are trying to use x before assigning a value to it.



Question : 24

What is Dynamic Typing feature of Python ?



Answer :

A variable pointing to a value of a certain type can be made to point to a value/object of different type. This is called Dynamic Typing. For example:

x = 10
print(x)
x = "Hello World"
print(x)




CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad