Crack CBSE Python Questions on Tokens
- Categories Python, Python Tokens, Python
Below are few CBSE Python Questions on Tokens (2 marks).
1)Identify which Python token are these?
- and
- _value
- True
- <=
Ans.
- Keyword
- Identifiers
- Boolean literals
- Relational Operator
2)Determine the type of literals below.
-19
0o12
0XFACE
Ans.
- Decimal integer literals
- Octal Integer Literals
- Hexadecimal Integer Literals
3)Identify which of the following as valid variable names, state reason if invalid.
- _ 100
- var.1
- break
- A463
- T 204
Ans.
- Valid as it begins with (underscore).
- Invalid, dot (.) is not allowed.
- Invalid, as break is a keyword.
- Valid
- Invalid, space is not allowed.
4)Identify the following literals as character/string literals:
- \t
- A1
- Nilam Sing#?9
- \56
Ans.
- Character
- String
- String
- String
5)What will be the sizes of following constants
- ‘\a’
- “\a”
- “it’s”
- ‘\”’
- “Reema\’s”
Ans.
- ‘\a’ – Size is 1 as there is 1 character and it is a string literal enclosed in single quotes
- “\a” – Size is 1 as there is 1 character enclosed in double quotes
- “it’s” – Size is 4. Python allows single quotes
- ‘\”’ – size is 1
- “Reema\’s”- Size is 7 (\’ is considered as single character)
6)Which of the following are valid comments?
- /* comment */
- */comment*/
- ‘’’ comment
- //comment
Ans.
Comments a and d is valid.
7)What is equivalent scientific notation of following:
- 5.18 x 108
- 25.4821
- 0.641 x 10-3
- 36.148
Ans.
- 5.18E + 08
- 2.54821E + 01
- 6.41E-04
- 3.6148E + 01
8)What is escape sequence for new line and vertical tab?
Ans. “\n” for new line and “\v” for Vertical tab.
9)Identify the following literals:
- 0.23
- True
- ‘b’
- “a”
Ans.
- Floating point literal
- Boolean literal
- Character literal
- String literal
10)Identify errors in following statements and correct them:
- number = 5,000
- byte x= = 3
- x/10 = y
- number = +20
Ans. correct statement:
- number = 5000
- byte = 3
- y= x/10
- number += 20
You may also like
Python Data Types
15 June, 2021
Python Tokens
15 June, 2021
Practice short problems on Python Random Module
25 April, 2020