• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
[email protected]
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Python Basics

Python Data Types

  • Categories Python Basics, Python, Python

In this post we will cover  Data Types in Python. You can watch our videos on Data Types in Python – Click Here

Q. 1 What is data type in python?
Ans.

  • Data types are the classification of data items.
  • It represents the value that states what operations can be performed on a specific data.
  • As everything is an object in Python programming, data types are classes and variables are instance (object) of these classes.
  • Following are the standard or built-in data type of Python:
    1. Numeric
    2. String
    3. Boolean
    4. List
    5. Tuple
    6. Set
    7. Dictionary

Q. 2 What is difference between mutable/immutable types in Python?
Ans:

Mutable Objects can change their state or contents e.g. list, Dictionary
Immutable Objects can’t be changed after it is created. These are of in-built types like int, float, bool, string, tuple.

Q. 3 What is Dynamic Typing?
Ans.
A variable pointing to a value of certain type can be made to point to value /object of different type. This is called Dynamic Typing
E.g.
       X = 20
       print (X)
       X = 20.5
       print (X)
       X = “Yes”
       print (X)

Q. 4 What does the type() function return?
Ans. The type() function returns the type of the specified object.

a = ('apple', 'banana', 'cherry')
b = "Hello World"
c = 33

x = type(a)
y = type(b)
z = type(c)

a = type(True)
b = type ({1:2})
c = type(23.5)

Output:

<class 'tuple'>
<class 'str'>
<class 'int'>
<class 'bool'>
<class 'dict’>
<class 'float’>

Q. 5 How do you do type conversion in Python?
Ans. We use following functions to convert

    1. int() – To convert any string, float to int
    2. float() – To convert any number to float
    3. str() – To convert any number to string
    4. bool() – To convert any number to Python
    5. list() – to convert any other type to tuple.
    6. tuple() To convert any other sequence to tuple
    7. dict() – To convert any other sequence to dict

Q. 8 What is list in python?
Ans.
A list contains items separated by commas and enclosed within square brackets ([]).
e.g.
      L1 = [ ‘Roshani’, 546 , 3.20, ‘Priya’, 65.3 ]
      L2 = [123, ‘jay’]

Q. 9 Write a short note on numeric data types.
Ans.

  • Numeric data type represent the data which has numeric value.
  • Numeric value can be integer, floating number or even complex numbers.
  • These values are defined as int, float and complex class in Python.

Q. 10 What is Complex data type in python? Give an example of same.
Ans.

  • Complex number is represented by complex class.
  • It is specified as (real part) + (imaginary part)j.
  • For example : 2.3 + 3j

Q. 11 Write a short note on Dictionary in python.
Ans.

  • Dictionaries are hash table type.
  • They are enclosed by curly braces ({ }) and values can be assigned and accessed using square braces ([]).
  • dict = {‘name’: ‘Riya’,’code’:2458, ‘dept’: ‘sales’}

Q. 12 What are tuples? Give one example.
Ans.

  • A tuple consists of a number of values separated by commas. Unlike lists, however, tuples are enclosed within parentheses. It is read only list
  • T1 = ( ‘abcd’, 145 , 2.23, ‘john’, 70.2 )
  • T2= (123, ‘john’)

Q.13 Explain Boolean data type.
Ans.

  • The bool data type is used to represent boolean values – True or False.
  • The data type can’t contain any other value.
  • True and False with capital ‘T’ and ‘F’ are valid booleans otherwise python will throw an error.

Q.14 Identify whether following are mutable or immutable types
           (i) String  (ii) Dictionary  (iii) float  (iv) List

Ans.    

(i) String – immutable
(ii) Dictionary – mutable
(iii) float– immutable
(iv) List – mutable

Q. 15 Write a Python program to test if a variable is a list or tuple or a set.
Ans.

x = eval(input(“Enter list, tuple or set”))
if type(x) is list:
print('x is a list')
elif type(x) is set:
print('x is a set')
elif type(x) is tuple:
print('x is a tuple')
else:
print('Neither a list or a set or a tuple.')

Q. 16 Write a Python program which accepts a sequence of comma-separated numbers from user and generate a list and a tuple with those numbers.
Ans.

values = input("Input some comma separated numbers : ")
list = values.split(",")
tuple = tuple(list)
print('List : ',list)
print('Tuple : ',tuple)
  • Share:
author avatar
Simply Coding

Previous post

Python Tokens
June 15, 2021

Next post

Java Theory - Java Basics
June 15, 2021

You may also like

Python function
Python function
3 July, 2021
for & while
Learn Python for & while
19 June, 2021
Queue
Python Queue
17 June, 2021

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now