Search Header Logo
Data types in python

Data types in python

Assessment

Presentation

Other

5th Grade

Easy

Created by

s tobgyal

Used 11+ times

FREE Resource

12 Slides • 3 Questions

1

​Data types in Python

2

​Data types in Python

​~are used to define the type of a value assigned to a variable

~There are different types of data types in Python

3

​Some of the data types are:

String data typesstr (text)

Numeric data typesint, float, complex

Boolean typebool

Sequence typeslist, tuple, range

Set data typesset, frozenset

Binary typesbytes, bytearray, memoryview

Mapping data typedict

4

String/Text

Group of characters/text surrounded by 'single' or "double" quotation marks.

 

Example:

my_Name= "Sonam Tobgyal@12345"

5

We can also assign multiline string using triple quotes..

 

Example:

" " "This is an example of

Multiline string used in

Python programming language " " "

6

Multiple Choice

Mr. Torma is a python programmer. He has assinged"Jigdrel Dorji" to the variable my_name. How would you help Torma to print the value assigned in the programme?

1

input(my_name)

2

print(my_name)

3

#my_name

4

"Jigdrel Dorji"

7

Numbers/numeric:

There are three numeric types in Python

  • int (whole number)

  • float (decimal)

  • complex (real+imaginary)

8

~which represents one of the two values i.e. True or False.

~In programming we often need to know if an expression is

true or false

~When we compare two values, the expression is evaluated and Python returns the Boolean answer:

Example:

1= =1 is True whereas 2<1 is False.

​ boolean

9

Data type conversion:

~We can convert from one type to another with the int(), float(), and complex() methods:

**We cannot convert complex numbers into another number

​ int() - integer, a float (by removing all decimals), or a string

Example:

x = int(1)   # integer----- 1
y = int(2.8# floating to integer-----2
z = int("3"# string to integer----- 3

10

Example:

x = float(1)     # integer to float---- 1.0
y = float(2.8)   # floating to float------2.8
z = float("3")   # string to float------3.0

  • float() - integer, float, string, complex

11

str() - constructs a string from a wide variety of data types, including strings, integer literals and float literals

x = str("s1"# x will be 's1'
y = str(2)    # y will be '2'
z = str(3.0)  # z will be '3.0'

12

Multiple Choice

What is the data type in python if my_age=25

1

string

2

boolean

3

integer

4

floating

13

Multiple Choice

Which of the following is not a valid data type in Python?

1

array

2

int

3

float

4

boolean

14

​type function:

~is used to find out the type of data assigned to a variable .

Example:

x=50

print(type(x)) #<class 'int'>

y=2.5

print(type(y))#<class 'float'>

Example:

a="ST"

print(type(a)) #<class 'str'>

b=2+0j

print(type(b))#<class 'complex'>

15

id() function
~is used to get the address of an object where it was stored in memory.

Example:
x="100"
print(id(x))


​Data types in Python

Show answer

Auto Play

Slide 1 / 15

SLIDE