CLASS 8 DATA TYPES IN PYTHON

 

DATA TYPES IN PYTHON

A. Tick the correct option

1.  Which of the following is not a valid variable name?

ANS1. a. Print

2.  Which of the following is not a string?

  ANS2. a. 89

3.  How many types of number data type are there in Python?

ANS C. 4

4.  Which of the following is a data type?

ANS A. TUPLE

5.  Which of the following will you use to access a value stored in a dictionary?

ANS C. [ ]

B. Fill in the blanks

1.  A multiline string spreads across multiple lines.

2.  Data type is used to represent data in the memory of the computer.

3.  A tuple can consist of different types of values.

4.   A conditional statement can also be called a decision making statement.

5.   The IF conditional statement has code for the condition being true only.

C  Write the output of the following code snippets.

1. >>> number_of_pages=200

>>>print(number_of_pages)

OUTPUT is 200

2. Given a list

lst=["Monday","Tuesday","Wednesday","Thursday",

"Friday","Saturday"]

a. What statements will you write to print the elements

stored at even indices?

a. print(lst[0,2,4])

b. Write a statement to replace incorrect spelling with the correct spelling of Friday.

b. lst[5]=Friday

print(lst)

c. Write a statement to print the number of elements in the list.

c. print(len(lst))

d. Write a statement to print the first element of this list.

d. print(lst[0])


3. fruits=["apple,"mango","orange"]

numbers=(5,4,3)

alphabets={'a':'apple','b':'ball','c':'cat'}

print(fruits)

print(numbers)

print(alphabets['b'])

OUTPUT

       ['apple', 'mango', 'orange']
       (5, 4, 3)
        ball
     4. >>>list1=[1,2,3,4]
        >>>list2=['i','love','numbers']
        >>>print(list1+list2)
       output 
        [1, 2, 3, 4, 'i', 'love', 'numbers']
      5. num=2
           if num>=0:
              print("Number is positive or zero.")
           else:
              print("Negative number")
         
        OUTPUT- Number is positive or zero

D. Short answer questions
1. What is number data type? Write its syntax and and 
example statement.
Ans1. The number data type or numeric literal is used to
store numeric values. Numeric literals are immutable
Syntax; <numeric name>=<numeric value>
 for eg. num1=30
2. What is the use of escaping in strings?
Ans2. Escaping a string means to reduce ambiguity in quotes (and other characters) used in that string. For instance, when you're defining a string, you typically surround it in either double quotes or single quotes:

"Hello, World."

But what if the string had double quotes within it?

"Hello "World.""

Now we have ambiguity - the software doesn't know where my string ends. one solution is to use single quotes around the string:

'Hello "World."'

Or I can escape my quotes:

"Hello \"World.\""

Any quote that is preceded by a slash is escaped and understood to be part of the value of the string.

3. Write three points about List data type in Python.

Ans3. 1. A list is a series of different values. For example, a list of items,

               students, colors and so on.

           2. A list can be read as well as written.

           3. A list is enclosed in square brackets [].

4. What are the different conditional statements used in Python?

Ans4. Following are the conditional statements used in Python:-

         1. If statement 

         2 if-else statement  

         3 if and else-if (or elif) statement

5. What is a mutable data type?

Ans5. Mutable data types are the data types whose values can be 

modified after they are created eg list, dictionary etc.

6. Write the statement to print the maximum element present in 

a list of numbers.

Ans6. b1=[2,6,88,55]

           print(max(b1)) 

                 

Comments

Popular posts from this blog

CLASS 8 PRACTICAL PAPER

HTML FORMS