Chapter 3 :- PYTHON FUNDAMENTAL
DEFINE THE TERMS
1. Constant :- A data item that never changes its value during a program run.
2. Identifier :- Name given by user for a part of the program.
3. Keyword :- Reserved word having special meaning and purpose.
4. Lexical unit :- Other name of taken.
5. Literals :- Constant
6. Token :- The smallest individual unit in a program
7. String literal :- Sequence of characters enclosed in any type of quotes
8. Variable :- Named stored location whose value can be manipulated during program run.
9. Expression :- Legal combination of symbols and values that together represents a value.
1. What is the difference between a keyword and an identifier ?
SOLUTION :-
Keyword is a special word that has a special meaning and purpose. Keywords are reserved and are a few. For example, if, elif, else etc. are keywords.
Identifier is a user-defined name given to a part of a program viz. variable, object, function etc. Identifiers are not reserved. These are defined by the user but they can have letters, digits and a symbol underscore. They must begin with either a letter or underscore. For instance, _chk, chess, trial etc. are identifiers in Python.
2.What are literals in Python? How many types of literals are allowed in Python?
SOLUTION :-
Literals mean constants i.e., the data items that never change their value during a program run. Python allows five types of literals:
(i) String literals
(ii) Numeric literals
(iii) Boolean literals
(iv) Special Literal None
(v) Literal Collections like tuples, lists etc.
3.How many types of strings are supported in Python?
SOLUTION :-
Python allows two string types:
(i) Single-line Strings :- Strings that are terminated in single line
(ii) Multi-line Strings :- Strings storing multiple lines text.
4. What factors guide the choice of identifiers in programs?
SOLUTION :-
(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 under-score) should be included in the identifier.
5. How can you create multi-line strings in Python?
SOLUTION :- Multi-line strings can be created in two ways:
(a) By adding a backslash at the end of normal
single-quote or double-quote strings e.g.,
Text =
"Welcome \
Το\
Python"
(b) By typing the text in triple quotation marks. (No backslash needed at the end of line) e.g.,
Str1="""Welcome
Το
Python
"""
6.What is None literal in Python ?
SOLUTION :-
Python has one special literal called None.
The None literal is used to indicate something that has not yet been created in simple words, or absence of value. It is also used to indicate the end of lists in Python.
7.What is the difference between an expression and a statement in Python ?
SOLUTION :-