Selfstudys Com File
Selfstudys Com File
Example:
1 stg='ABCD'
2 print(stg.lower())
Output: abcd
Ans: The sequences in Python are indexed and it consists of the positive as well as
negative numbers. The numbers that are positive uses ‘0’ that is uses as first index
and ‘1’ as the second index and the process goes on like that.
The index for the negative number starts from ‘-1’ that represents the last index in
the sequence and ‘-2’ as the penultimate index and the sequence carries forward
like the positive number.
The negative index is used to remove any new-line spaces from the string and allow
the string to except the last character that is given as S[:-1]. The negative index is
also used to show the index to represent the string in correct order.
3 Special meaning words of Pythons, fixed for specific functionality are called ..........
.
1. Identifiers
2. functions
3. Keywords ✓
4. literals
1. Identifiers ✓
2. functions
3. Keywords
4. literals
5 Data items having fixed value are called .......... .
1. Identifiers
2. functions
3. Keywords
4. literals ✓
1. name = Jiya
2. name = 'Jiya' ✓
3. name = "Jiya" ✓
4. name = (Jiya)
1. my name
2. _myname ✓
3. myname ✓
4. my-name
1. myname
2. "Radha" ✓
3. 24.5 ✓
4. 24A
1. strings
2. characters ✓
3. integers
4. none of these
1. 0.1725E-2
2. 0.1725E+2 ✓
3. 1725E2
4. 0.1725E2 ✓
1. else
2. import
3. print
4. all of these ✓
13 To convert the read value through input( ) into integer type, ..........( ) is used.
1. floating
2. float
3. int ✓
4. integer
14 What are tokens in Python ? How many types of tokens are allowed in Python ?
Examplify your answer.
Answer
The smallest individual unit in a program is known as a Token. Python has
following tokens:
Answer
Yes, nongraphic characters can be used in Python with the help of escape
sequences. For example, backspace is represented as \b, tab is represented as \t,
carriage return is represented as \r.
16 Which of these is not a legal numeric type in Python ? (a) int (b) float (c) decimal.
Answer
decimal is not a legal numeric type in Python.
17 What are operators ? What is their function ? Give examples of some unary and
binary operators.
Answer
Operators are tokens that trigger some computation/action when applied to
variables and other objects in an expression. Unary plus (+), Unary minus (-),
Bitwise complement (~), Logical negation (not) are a few examples of unary
operators. Examples of binary operators are Addition (+), Subtraction (-),
Multiplication (*), Division (/).
18 What do you understand by undefined variable in Python ?
Answer
In Python, a variable is not created until some value is assigned to it. A variable is
created when a value is assigned to it for the first time. If we try to use a variable
before assigning a value to it then it will result in an undefined variable. For
example:
The first line of the above code snippet will cause an undefined variable error as
we are trying to use x before assigning a value to it.
Answer
The error in the above code is that we have mentioned two variables X, Y as
Lvalues but only give a single numeric literal 7 as the Rvalue. We need to specify
one more value like this to correct the error:
X, Y = 7, 8
a, b, c = 10, 20, 30
p, q, r = c - 5, a + 3, b - 4
print ('a, b, c :', a, b, c, end = '')
print ('p, q, r :', p, q, r)
Output
a, b, c : 10 20 30p, q, r : 25 13 16
22 Write a program that displays a joke. But display the punchline only when the user
presses enter key.
(Hint. You may use input( ))