Python Token (2023-24)
Python Token (2023-24)
Python Token (2023-24)
1. What is comment?
EX 1: #this is a comment
print ("Hello, World!")
No output
2. What is token?
Ans: The smallest individual unit in a program is called as
token or lexical unit. The different types of token are
• Keywords
• Identifiers
• Literals
• Operators
• Punctuators/Delimiters
3. What is identifier?
Ans: A Python identifier is the name given to a variable,
function, class, module or other object. An identifier can begin
with an alphabet (A – Z or a – z), or an underscore (_) and can
include any number of letters, digits, or underscores. Spaces
are not allowed. Python will not accept @, $ and % as
identifiers. Furthermore, Python is a case-sensitive language.
Thus,
Hello and hello both are different identifiers
4. What is keyword?
Keywords are the reserved words in Python used by Python
interpreter to recognize the structure of the program.
5. What is literal?
Ans: Literal are also called constant values which are the data
items having fixed values. Python allows different literal that
are string, numeric, Boolean etc.
Ex: x=23(Here 23 is a numeric literal)
6. What is operator?
Ans: Operators are special symbols which represent
computation. They are applied on operand(s), which can be
values or variables. Same operators can behave differently on
different data types. Operators when applied on operands form
an expression. Operators are categorized as Arithmetic,
Relational, Logical and Assignment. Value and variables when
used with operator are known as operands.
Arithmetic operators
15>25 False
And
And operator True and True True
Not
Not Operator not False True
Assignment operators
= X=5
+= X+=5 X=X+5
-= X-=5 X=X–5
*= X*=5 X=X * 5
/= X/=5 X=X / 5
7. What is a variable?
Ans: Variable is a named memory location.Variables are
containers for storing data values. Python has no command
for declaring a variable. A variable is created the moment you
first assign a value to it.
A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume). Rules for
Python variables:
myvar2 = 78
x = 20 int
x = 20.5 float
x = 1j complex
x = True bool
8. What is delimiter/punctuator?
Ans: A punctuator is a token that has syntactic and semantic
meaning to the compiler, but the exact significance depends on the
context. The following nine ASCII characters are the separators:
(){}[];,.\#@:=‘“
Ex:
\n This represents a newline
• Ex1: a=3.5
b=int(a)+2
print(b)
Output
5
(Note:Here output is not 5.5 because a converted to int so
instead of 3.5 it will take 3)
• Ex2:a=3
b=float(a) * 2
print(b)
Output
6.0
(Note: Instead of 6 the output will be 6.0 because 3 got converted
to 3.0 by typecasting)