class3
class3
===================
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")
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 ...")
->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 ....')
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")
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:]
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]
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")