BasicDataTypeS
BasicDataTypeS
#number
# Python program to
# demonstrate numeric value
'''a = 5
print("Type of a: ", type(a))
b = 5.0
print("\nType of b: ", type(b))
c = 2 + 4j
print("\nType of c: ", type(c))'''
'''####################
# Python Program for
# Creation of String
# Creating a String
# with single Quotes
String1 = 'Welcome to World'
print("String with the use of Single Quotes: ")
print(String1)
# Creating a String
# with double Quotes
String1 = "I'm Ravi"
print("\nString with the use of Double Quotes: ")
print(String1)
print(type(String1))
############################
# Python Program to Access
# characters of String
String1 = "Summercamp"
print("Initial String: ")
print(String1)
#################################
#String Methods
txt = "python is fun!"
x = txt.capitalize()
print (x)
###########
txt = "Hello, And Welcome To My World!"
x = txt.casefold()
print(x)
###############
txt = "banana"
x = txt.center(20)
print(x)
###########
txt = "I love apples, apple are my favorite fruit"
x = txt.count("apple")
print(x)
##############
txt = "Hello, welcome to my world."
x = txt.endswith(".")
print(x)
###############
txt = "H\te\tl\tl\to"
x = txt.expandtabs(2)
print(x)
#################
txt = "Hello, welcome to my world."
x = txt.find("welcome")
print(x)
##############
txt = "For only {price:.2f} dollars!"
print(txt.format(price = 49))
#############
txt = "Hello, welcome to my world."
x = txt.index("welcome")
print(x)
################
txt = "Company12"
x = txt.isalnum()
print(x)
#########
txt = "CompanyX"
x = txt.isalpha()
print(x)
#################
txt = "\ratu"
x = txt.isdecimal()
print(x)
###############
txt = "hello world!"
x = txt.islower()
print(x)
#################
txt = "THIS IS NOW!"
x = txt.isupper()
print(x)
################
txt = "Hello my FRIENDS"
x = txt.lower()
print(x)
#############
txt = "Hello my FRIENDS"
x = txt.lower()
print(x)
####################
txt = " banana "
x = txt.lstrip()
print("of all fruits", x, "is my favorite")
##############
txt = "I like bananas"
x = txt.replace("bananas", "apples")
print(x)
###################
txt = " banana "
x = txt.rstrip()
print("of all fruits", x, "is my favorite")
##################
txt = " banana "
x = txt.strip()
print("of all fruits", x, "is my favorite")
##################
txt = "Hello My Name Is PETER"
x = txt.swapcase()
print(x)
################
txt = "Welcome to my world"
x = txt.title()
print(x)
###################
txt = "Hello my friends"
x = txt.upper()
print(x)
#####################
#List
# Python program to demonstrate
# Creation of List
# Creating a List
List = []
print("Initial blank List: ")
print(List)
###############
thislist = ["orange", "mango", "kiwi", "pineapple", "banana"]
thislist.sort()
print(thislist)
##############
thislist = [100, 50, 65, 82, 23]
thislist.sort()
print(thislist)
#############
thislist = ["orange", "mango", "kiwi", "pineapple", "banana"]
thislist.sort(reverse = True)
print(thislist)
###########
thislist = [100, 50, 65, 82, 23]
thislist.sort(reverse = True)
print(thislist)
###################
thislist = ["apple", "banana", "cherry"]
mylist = thislist.copy()
print(mylist)
##################
thislist = ["apple", "banana", "cherry"]
mylist = list(thislist)
print(mylist)
#################
list1 = ["a", "b", "c"]
list2 = [1, 2, 3]
list3 = list1 + list2
print(list3)
##############
list1 = ["a", "b" , "c"]
list2 = [1, 2, 3]
for x in list2:
list1.append(x)
print(list1)
#################
list1 = ["a", "b" , "c"]
list2 = [1, 2, 3]
list1.extend(list2)
print(list1)
###################
fruits = ['apple', 'banana', 'cherry', 'orange']
fruits.clear()
#################
fruits = ['apple', 'banana', 'cherry', 'orange']
x = fruits.copy()
###################
fruits = ['apple', 'banana', 'cherry']
x = fruits.index("cherry")
#####################
fruits = ['apple', 'banana', 'cherry']
fruits.pop(1)
###############
fruits = ['apple', 'banana', 'cherry']
fruits.remove("banana")
#################
fruits = ['apple', 'banana', 'cherry']
x = fruits.count("cherry")
print(x)
##################Tuple
# Python program to demonstrate
# creation of Set
# Creating a Tuple
# with nested tuples
Tuple1 = (0, 1, 2, 3)
Tuple2 = ('python', 'Ravi')
Tuple3 = (Tuple1, Tuple2)
print("\nTuple with nested tuples: ")
print(Tuple3)
##################
# Python program to
# demonstrate accessing tuple
######################
thistuple = ("apple", "banana", "cherry")
print(thistuple)
###########
thistuple = ("apple", "banana", "cherry", "apple", "cherry")
print(thistuple)
###########
thistuple = ("apple", "banana", "cherry")
print(len(thistuple))
###################
tuple1 = ("apple", "banana", "cherry")
tuple2 = (1, 5, 7, 9, 3)
tuple3 = (True, False, False)
print(tuple1)
print(tuple2)
print(tuple3)
####################
tuple1 = ("abc", 34, True, 40, "male")
#################
thistuple = tuple(("apple", "banana", "cherry")) # note the double round-brackets
print(tuple1)
print(thistuple)
#############
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
############
thistuple = ("apple", "banana", "cherry")
print(thistuple[-1])
###########
thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(thistuple[2:5])
##########
thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(thistuple[:4])
###############
thistuple = ("apple", "banana", "cherry", "orange", "kiwi", "melon", "mango")
print(thistuple[2:])
##############
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.count(5)
print(x)
###############
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
x = thistuple.index(8)
print(x)
#####################
thistuple = ("apple", "banana", "cherry")
y = ("orange",)
thistuple += y
print(thistuple)
###############
thistuple = ("apple", "banana", "cherry")
for x in thistuple:
print(x)
#############
tuple1 = ("a", "b" , "c")
tuple2 = (1, 2, 3)
print(mytuple)
#############
thisset = {"apple", "banana", "cherry"}
print(thisset)
################
thisset = {"apple", "banana", "cherry", "apple"}
print(thisset)
###############
fruits = {"apple", "banana", "cherry"}
fruits.add("orange")
print(fruits)
'##################
fruits = {"apple", "banana", "cherry"}
fruits.clear()
print(fruits)
#################
ruits = {"apple", "banana", "cherry"}
x = fruits.copy()
print(x)
############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.difference(y)
print(z)
###############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.difference_update(y)
print(x)
###############
fruits = {"apple", "banana", "cherry"}
fruits.discard("banana")
print(fruits)
###############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)
###############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.intersection_update(y)
print(x)
#############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "facebook"}
z = x.isdisjoint(y)
print(z)
#################
x = {"a", "b", "c"}
y = {"f", "e", "d", "c", "b", "a"}
z = x.issubset(y)
print(z)
#############
x = {"f", "e", "d", "c", "b", "a"}
y = {"a", "b", "c"}
z = x.issuperset(y)
print(z)
##################
fruits = {"apple", "banana", "cherry"}
fruits.pop()
print(fruits)
###################
fruits = {"apple", "banana", "cherry"}
fruits.remove("banana")
print(fruits)
#################
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.symmetric_difference(y)
print(z)
#############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.symmetric_difference_update(y)
print(x)
###############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.union(y)
print(z)
###############
x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
x.update(y)
print(x)
##################
#Dictionary
# Creating an empty Dictionary
Dict = {}
print("Empty Dictionary: ")
print(Dict)
# Creating a Dictionary
# with Integer Keys
Dict = {1: 'Ravi', 2: 'Kumar', 3: 'CBIT'}
print("\nDictionary with the use of Integer Keys: ")
print(Dict)
# Creating a Dictionary
# with Mixed keys
Dict = {'Name': 'Ravi', 1: [1, 2, 3, 4]}
print("\nDictionary with the use of Mixed Keys: ")
print(Dict)
# Creating a Dictionary
# with dict() method
Dict = dict({1: 'Ravci', 2: 'For', 3:'CBIT'})
print("\nDictionary with the use of dict(): ")
print(Dict)
# Creating a Dictionary
# with each item as a Pair
Dict = dict([(1, 'Ravi'), (2, 'CBIT')])
print("\nDictionary with each item as a pair: ")
print(Dict)
##################
# Python program to demonstrate
# accessing a element from a Dictionary
# Creating a Dictionary
Dict = {1: 'Ravi', 'name': 'Kumar', 3: 'CBIT'}