Python fundamental

 

Python Fundamentals

A. Multiple choice questions.

Q1. Special meaning words of Pythons, fixed for specific functionality are called .......

(a)  Identifiers                                          (b) functions

(c) Keywords                                        (d) literals

Q2. Names given to different parts of a Python program are.......... .

(a)  Identifiers                                       (b) functions

(c) Keywords                                            (d) literals

Q3. Data items having fixed value are called.......... .

(a)  Identifiers                                          (b) functions

(c) Keywords                                           (d) literals

Q4. Which of the following is/are correct ways of creating strings?

(a)  name = Jiya                                      (b) name = 'Jiya'

(c) name = "Jiya"                                 (d) name = (Jiya)

Q5. Which of the following are keyword(s)?

(a)  name                                                  (c) Print

(c) print                                                  (d) input

Q6. Which of the following are valid identifiers?

(a)  my name                                            (b) _myname

(c) myname                                          (d) my-name

Q7. Which of the following are literals?

(a) Myname                                                   (b) "Radha"

(c) 24.5                                                        (d) 24A

Q8. Escape sequences are treated as .......... .

(a)  strings                                                (b) characters

(c) integers                                  (d) none of these

Q9. Which of the following is an escape sequence for a tab character?

(a)  \a                                             (b) \t

(c) \n                                             (d) \b

Q10.    Which of the following is an escape sequence for a newline character?

(a)  \a                                             (b) \t

(c) \n                                          (d) \b

Q11. Which of the following is not a legal integer type value in Python?

(a)  Decimal                                 (b) Octal

(c) Hexadecimal                         (d) Roman

Q12. Which of the following symbols are not legal in an octal value?

(a)  7                                              (b) 8

(c) 9                                           (d) 0

Q13. Value 17.25 is equivalent to

(a)  0.1725E-2                              (b) 0.1725E+2

(c) 1725E2                                   (d) 0.1725E2

Q14. Value 0.000615 is equivalent to

(a)   615E3                                   (b) 615E-3

(c) 0.615E3                                  (d) 0.615E-3

Q15. Which of the following is/are expression(s)?

(a) a+b-5                             (b) a

(c) -5                                       (d) b-5

Q16. The lines beginning with a certain character, and which are ignored by a compiler and not executed, are called ..........

(a)  operators                               (b) operands

(c) functions                                (d) comments

Q17. Which of the following can be used to create comments?

(a)  //                                              (b) #

(c) '''                                              (d) ''' . . . '''

Q18. Which of the following functions print the output to the console?

(a)  Output( )                                (b) Print( )

(c) Echo( )                                    (d)print( )

Q19. Select the reserved keyword in Python.

(a)  else                                         (b) import

(c) print                                         (d) all of these

Q20. The input( ) returns the value as .......... type.

(a)  Integer                                    (b) string

(c) floating point                         (d) none of these

Q21. To convert the read value through input( ) into integer type, ..........( ) is used.

(a)  floating                                   (b) float

(c) int                                         (d) integer

Q22. To convert the read value through input( ) into a floating point number, ..........( ) is used.

(a)  floating                                   (b) float

(c) int                                            (d) integer

Q23. To print a line a text without ending it with a newline, .......... argument is used with print( )

(a)  sep                                          (b) newline

(c) end                                       (d) next

Q24. The default separator character of print( ) is ..........

(a)  tab                                           (b) space

(c) newline                                  (d) dot

Q25. To give a different separator with print( ) .......... argument is used.

(a)  sep                                       (b) separator

(c) end                                          (d) tab

B. Fill in the Blanks

Q1. A keyword is a reserved word carrying special meaning and purpose.

Q2. Identifiers are the user defined names for different parts of a program.

Q3. Literals are the fixed values.

Q4.Operators are the symbols that trigger some computation or action.

Q5.An expression is a legal combination of symbols that represents a value.

Q6. Non-executable, additional lines added to a program, are known as comments.

Q7. In Python, the comments begin with # character.

Q8.Python is a case sensitive language.

Q9. The print( ) function prints the value of a variable/expression.

Q10. The input( ) function gets the input from the user.

Q11. The input( ) function returns the read value as of string type.

Q12. To convert an input( )'s value in integer type, int( ) function is used.

Q13.  To convert an input( )'s value in floating-point type, float( ) function is used.

Q14. Strings can be created with single quotes, double quotes and triple quotes.

 

C. State True or False.

Q1. Keywords can be used as identifier names. False

Q2. The identifiers in Python can begin with an underscore. True

Q3. 0128 is a legal literal value in Python. False

Q4. 0x12EFG is a legal literal value in Python. False

Q5. 0123 is a legal literal value in Python. True

Q6. Variables once assigned a value can be given any other value. True

Q7. Variables are created when they are first assigned their value. True

Q8. Python variables support dynamic typing. True

Q9. You can rename a keyword. False

Q10. String values in Python can be single line strings, and multi-line strings. True

Q11. A variable can contain values of different types at different times. True

Q12. Expressions contain values/variables along with operators. True

 

D. Answer the following questions.

Q1. What is meant by token? Name the tokens available in Python.

Ans. The smallest individual unit in a program is known as a token or a lexical unit. Python has following tokens.

(a)  Keywords    (b) Literals    (c) Identifiers   (d) Punctuators   (e) Operators

Q2. What are keywords? Can keywords be used as identifier?

Ans. Keywords are the words that convey a special meaning to the language compiler/interpreter. No, keywords cannot be used as identifier.

Q3. What is an identifier? What are the identifier forming rules of Python?

Ans. Identifiers are the names given to the different parts of the program such as, variables, objects, classes, functions, lists, dictionaries, etc.

       Rules for forming identifier:

(a)  Identifier can have letters, number and underscore.

(b)  The first character must be a letter or underscore.

(c)  Names are case sensitive. Upper and lower-case letters are different.

(d)  An identifier must not be a keyword of Python.

(e)  An identifier cannot contain any special character except for underscore (_).

Q4. Is Python case sensitive? What is meant by the term ‘case sensitive’?

Ans. Yes, Python is case sensitive. Case sensitive meant upper and lower case are different.

Q5. What are literals? How many types of literals are available in Python?

Ans. Literals are data items that have a fixed value. Python has following literals.

(a)  String literals  (b) Numeric literals    (c) Boolean literals    (d) Special literal None     (e) Literal Collections

 

Q6. How many types of integer literals are allowed in Python?

Ans. There are three types of Integer literals: Decimal Integer Literals, Octal Integer Literals, and Hexadecimal Integer Literals.

Q7. Why are characters \, ‘,” and tab typed using escape sequences?

Ans. When these characters are typed without escape sequence, these carry special meaning. It we want to type them as it is, then escape sequences should be used.

Q8. Which escape sequences represent the newline character and backslash character? How many characters does an escape sequence represent?

Ans. \n represents newline character and \\ represents backslash. Escape sequence represents one character.

Q9. What are string-literals in Python? How many ways, can you create String literals in Python? Are there any differences in them?

Ans. The text enclosed in quotes forms a string literal in Python. We can create strings in two ways: keeping the text within single quotes or double quotes. No, there is no difference between them.

Q10. What is meant by a floating-point literal in Python? How many ways can a floating literal be represented into?

Ans. Floating-point literals are numbers having fractional parts. These may be written in one of the two forms called Fractional Form or the Exponent Form.

Q11. What are the two Boolean literals in Python? Name some built-in

Ans. Two Boolean literals in Python are: True and False.

Q12. Name some built-in literals of Python.

Ans. Boolean literals True, False and special literal None are some built-in literals of pythons.

Q13. What is an expression in Python?

Ans. An expression is any legal combination of symbols that represents a value. An expression represents something, which Python evaluates and which then produces a value. Ex: b+4

Q14. What is a statement in Python? How is a statement different from expression?

Ans. A statement is a programming instruction that does something or perform some action. Ex: if b>a. An expression represents something but a statement takes some action.

Q15. What is a comment? In how many ways can you create comments in Python?

Ans. Comments are the additional readable information, which is read by the programmers but ignored by Python interpreter. We can create comments in two ways: comments begin with symbol # (hash) and end with the end of physical line and multiline (docstring) placed within triple quote (single quote or triple quote).

       Ex:    #This is single line comment

     ‘‘‘This is the

                   Multiline comment’’’  

 

Q16. What is the difference between full-line comment and inline comment?

Ans.A full-line comment is written from the beginning of the physical line with symbol # (hash). Whereas, an in-line comment also begins with the symbol # (hash), but is placed after some code in the line.

Ex: #this is full-line comment

      a = b+5 #this is in-line comment

Q17. What is a block or suite in Python? How is indentation related to it?

Ans. A block or suite in Python is a group of statements which is part of another statement or function. These statements are kept at same indentation level.

Q18. What is a variable?

Ans. A variable in Python represents named location that refers to a value and whose values can be used and processed during program run.

Q19. Why a variable is called symbolic variable? 

Ans. A variable is called symbolic variable because in Python variable are not the memory locations but merely named labels referring to the valued stored in the memory locations.

Q20. What do you mean by dynamic typing of a variable?

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

Q21. What is the difference between a keyword and an identifier?

Ans. A keyword is a special word that has a special meaning and purpose. Keywords are reserved and are a few. An identifier is a user-defined name given to a part of program viz. variable, object, function etc.

Q22. How many ways are there in Python to represent an integer literal?

Ans.  Python allows three types of integer literals.

(a)  Decimal (base 10) integer literals

(b)  Octal (base 8) integer literals

(c)  Hexadecimal (base16) integer literals.

Q23. What factors guide the choice of identifiers in programs?

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

        (ii) Noreserved word or standard identifier should be used.

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

 

 

 

Comments

Popular posts from this blog

The Road Not Taken

Chapter 4 The Basic Writing Skills

The Fun They Had