0% found this document useful (0 votes)
3 views7 pages

class3

Uploaded by

kirpat1002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views7 pages

class3

Uploaded by

kirpat1002
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Data types in Python

===================

What is data type?


-----------------
Data types are used to store the different values at memory allocation.In Pyton
we do have following types of data types

->Int or integer data type


->Float or FLoat data type
->Str or String data type
->Bool or boolean data type
->Complex data type
->List data type
->Tuple data type
->Set data type
->Dict data type
->Bytes data type
->Bytearray data type
->Frozenset data type
->range data type
->None data type

->Int or integer data type:


==========================
Python supports Int or integer data type.It can be represent as decimal number from
0-9.It may be either + number or - number.

Ex1:
---
import time
x1=145
print('The value of x1 is:',x1)
print()
print('The data type is:',type(x1))
print()
x2=-167
print('The value of x2 is:',x2)
print()
print('The data type is:',type(x2))
print()
time.sleep(2)
print("End of an application")

->Float or FLoating data type:


=============================
Python supports float or floating data type.It can be represent as floating point
number or decimal point number.It may be eithet + floating point number or -
floating point number. In python 1.3e is also consider as floating data type.

Ex1:
---
import time
x1=145.67
print("The value of x1 is:",x1)
print()
print("The data type is:",type(x1))
print()
x2=-123.98
print("The value of x2 is:",x2)
print()
print("The data type is:",type(x2))
print()
time.sleep(2)
print("End of an application ...")

Ex2:
----
import time
y1=1.3e
print("The value of y1 is:",y1)
print()
print("The data type is:",type(y1))
print()
time.sleep(2)
print("End of an application ...")

OUTPUT:
======
:\Users\DELL\Desktop>Python test1.py
File "test1.py", line 2
y1=1.3e
^
SyntaxError: invalid syntax

Ex2:
===
import time
y1=1.3*10*10
print("The value of y1 is:",y1)
print()
print("The data type is:",type(y1))
print()
time.sleep(2)
print("End of an application ...")

Note:e means here expo value 10 to the power of 2 ===>10*10

Str or string data type:


=======================
->Python supports Str or string data type.String can be represent as collection of
one or more than one characeters enclosed with ('') or ("") or ('''''') or
("""""").

->While working with string data type space is also consider one character.
->Python supports positive index which starts 0 & ends end-1.It is also known as
forward direction.
->Python supports negative index which starts from -1 to end+1
->('''''') or("""""") is also used for multiline constent purpose

Ex1:
----
import time
str1='Core Python'
str2="Core Python"
str3='''Core Python'''
str4="""Core Python"""
str5='100'
str6="123.45"
str7="True"
print(str1)
print(str2)
print(str3)
print(str4)
print(str5)
print(str6)
print(str7)
print()
print(type(str1))
print(type(str2))
print(type(str3))
print(type(str4))
print(type(str5))
print(type(str6))
print(type(str7))
print()
time.sleep(2)
print('End of an application ....')

I will be a 'software developer' after end this program

Ex2:
----
import time
str1="I will be a 'software developer' after end this program"
print()
print(str1)
print()
print(type(str1))
print()
time.sleep(2)
print("End of an application")

I will be a 'software developer' after learning "Python" after 3 months

Ex3:
---
import time
str1='''I will be a 'software developer' after learning "Python" after 3 months'''
print()
print(str1)
print()
print(type(str1))
print()
time.sleep(2)
print("End of an application")

Ex4:
===
import time
str1="""I will be a 'software developer' after learning "Python" after 3 months"""
print()
print(str1)
print()
print(type(str1))
print()
time.sleep(2)
print("End of an application")

Ex5:
----
import time
str1='''HI GUYS
HOPE YOU ARE GETTING THE PYTHON
THANK YOU'''
print()
print(str1)
print()
print(type(str1))
print()
time.sleep(2)
print("End of an application ...")

HI GUYS
HOPE YOU ARE GETTING THE PYTHON
THANK YOU

Ex6:
----
import time
str1="""HI GUYS
HOPE YOU ARE GETTING THE PYTHON
THANK YOU"""
print()
print(str1)
print()
print(type(str1))
print()
time.sleep(2)
print("End of an application ...")

Ex7:
---
import time
str1="HI GUYS
HOPE YOU ARE GETTING THE PYTHON
THANK YOU"
print()
print(str1)
print()
print(type(str1))
print()
time.sleep(2)
print("End of an application ...")

OUTPUT:
======
SyntaxError: EOL while scanning string literal

Ex8:
----
import time
str1="Core Python"
print(str1)
print()
print(type(str1))
print("----Using possitive direction----")
print(str1[0])
print(str1[1])
print(str1[2])
print(str1[3])
print("------------------------------------")
print()
print("----Using negative direction----")
print(str1[-11])
print(str1[-10])
print(str1[-9])
print(str1[-8])
print("------------------------------")

Slice operator:
==============
Python supports slice operator.The main objective of slice operator is make the
pieces of the python object or string as per the application requirement. Following
are the syntax for slice operator

str1[begin:end(end-1):step]

form1
-----
str1[begin:]

Here end(end-1) and step is optional.The output of the string would be


from given position to till end of the string.

Ex1:
---
import time
str1="Core Python"
print(str1)
print()
print(type(str1))
print()
print("----Using slice operator----")
print("----Form1----")
print(str1[7:])
print("------")
print()
time.sleep(2)
print("End of an application")

form2:
=====
str1[:end(end-1]

Here begin and step is optional.The output of the string would be


from indexing position to till end-1 position.

Ex1:
---
import time
str1="Core Python"
print(str1)
print()
print(type(str1))
print()
print("----Using slice operator----")
print("----Form2----")
print(str1[:7])
print("------")
print()
time.sleep(2)
print("End of an application")

form3:
-----
str1[begin:end(end-1)]

Here step is optional.The output of the string would be from given position to till
end-1 th position.

Ex1:
---
import time
str1="Core Python"
print(str1)
print()
print(type(str1))
print()
print("----Using slice operator----")
print("----Form3----")
print(str1[3:8])
print("------")
print()
time.sleep(2)
print("End of an application")

You might also like