MENU

Chapter 8 Getting Started with Python Solutions

Question - 11 : -
What are literals in Python ? How many types of literals are allowed in Python ?

Answer - 11 : -

Literals mean constants i.e. the data items that never change value during a program run. Python allow five types of literals :

  1. String literals
  2. Numeric literals
  3. Boolean literals
  4. Special literal (None)
  5. Literal collections like tuples, lists etc.

Question - 12 : -
How many ways are there in Python to represent an integer literal ?

Answer - 12 : -

Python allows three types of integer literals :

  1. Decimal (base 10) integer literals.
  2. Octal (base 8) integer literals.
  3. Hexadecimal (base 16) integer literals.
For example, decimal 12 will be written as 14 as octal integer and as OXC as hexa decimal integer. (12)10 = (14)8 = (OXC)16. (as hexa decimal)

Question - 13 : -
How many types of strings are supported in Python ?

Answer - 13 : -

Python allows two string types :

1. Single line strings : Strings that are terminated in single line. For example :
str = ‘Oswal Books’
2. Multiple strings : Strings storing multiple lines of text. For example :
str = ‘Owal \
Books’
or str = ” ” ” Oswal
Books
” ” “

Question - 14 : -
What is “None” literal in Python ?

Answer - 14 : -

Python has one special literal called ‘None’. The ‘None’ literal is used to indicate something that has not yet been created. It is also used to indicate the end of lists in Python.

Question - 15 : -
What factors guide the choice of identifiers in Programs ?

Answer - 15 : -

  1. An identifier must start with a letter or underscore followed by any number of digits or/ and letters.
  2. No special character (other than under-score) should be included in the identifier.
  3. No reserved word or standard identifier should be used.
  4. Upper and lower case letters are different. All characters are significant.

Question - 16 : -
What will be the size of the following constants : “\a”. “\a”, “Manoj\’s”, ‘\”, “XY\ YZ”

Answer - 16 : -

‘\a’ – size is 1 as there is one character and it is a string literal enclosed in single quotes.
“\a” – size is 1 as there is one character enclosed in double quotes.
“Manoj\’s” – size is 7 because it is a string having 7 characters enclosed in double quotes.
“\” – size is 1. It is a character constant and is containing just one character \”.
“XY\ – size is 4. It is a multiline string create YZ” with \ in the basic string.

Question - 17 : -
What is the difference between a tuple and a list ?

Answer - 17 : -

A tuple is immutable i.e. cannot be changed. It can be operated on only. But a list is mutable. Changes can
be done internally to it.
tuple initialization: a = (2,4,5) list initialization: a = [2,4,5]

Question - 18 : -
Write various python modules convert the list to generate the output “one, two, three” ? a = [‘one’, ‘two’, ‘three’]

Answer - 18 : -

> > > a = [‘one’,’two’,’three’]
>>> ‘,’.join(a)
‘one,two,three’

Question - 19 : -
Is there a tool to help find bugs or perform static analysis?

Answer - 19 : -

Yes. PyChecker is a static analysis tool that finds bugs in Python source code and warns about code complexity and style. Pylint is another tool that checks if a module satisfies a coding standard, and also makes it possible to write plug-ins to add a custom feature.

Question - 20 : -
What is a tuple ?

Answer - 20 : -

A tuple is another sequence data type that is similar to the list. A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses.

Free - Previous Years Question Papers
Any questions? Ask us!
×