Skip to content

added new programs for python operator #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions #6_Python_Type_Conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Python code to demonstrate Type conversion
# int(a,base) : This function converts any data type to integer. ‘Base’ specifies the base in which string is if data type is string.
# float() : This function is used to convert any data type to a floating point number
# complex(): This function is used to convert any data type to complex data type
# bool(): This function is used to identify the value is 0 or not it return True or False

a=1
b="101010"

print ("Convert Value in integer data type",int(b,2),)

print ("Convert value in float data type",float(a),)

print ("convert value in complex data type",complex(a),)

print ("validiate value as boolen datatype",bool(a),)

# using ord(), hex(), oct()
# initializing integer
example = '4'

# printing character converting to integer
output = ord(example)
print ("After converting character to integer : ",end="")
print (output)

# printing integer converting to hexadecimal string
output = hex(50)
print ("After converting 56 to hexadecimal string : ",end="")
print (output)

# printing integer converting to octal string
output = oct(60)
print ("After converting 56 to octal string : ",end="")
print (output)

example=0
output = (bool(example))
print ("validating example value is 0 or not using bool function: ", end="")
print (output)

example=1
output = (bool(example))
print ("validating example value is 0 or not using bool function: ", end="")
print (output)

example=-1
output = (bool(example))
print ("validating example value is 0 or not using bool function: ", end="")
print (output)
73 changes: 73 additions & 0 deletions #7_Python_set_data_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# A set is an unordered collection of items. Every element is unique (no duplicates) and must be immutable (which cannot be changed).
#
# Operators for Sets
# Sets and frozen sets support the following operators:
#
# key in set-example # containment check
#
# key not in set-example # non-containment check
#
# set-1 == set-2 # set-1 is equivalent to set-2
#
# set-1 != set-2 # set-1 is not equivalent to set-2
#
# set-1 <= set-2 # set-1is subset of set-2 set-1 < set-2 # set-1 is proper subset of set-2 set-1 >= set-2 # set-1is superset of set-2
#
# set-1 > set-2 # set-1 is proper superset of set-2
#
# set-1 | set-2 # the union of set-1 and set-2
#
# set-1 & set-2 # the intersection of set-1 and set-2
#
# set-1 – set-2 # the set of elements in set-1 but not set-2
#
# set-1 ˆ set-2 # the set of elements in precisely one of set-1 or set-2
#

set1=set('abc')
set2=set('bcd')

output=set1|set2
print ("Output for : ", end="")
print (output)

print("Set1 = ", set1)
print("Set2 = ", set2)
print("\n")

# Union of set1 and set2
set3 = set1 | set2# set1.union(set2)
print("Union of Set1 & Set2: Set3 = ", set3)

# Intersection of set1 and set2
set4 = set1 & set2# set1.intersection(set2)
print("Intersection of Set1 & Set2: Set4 = ", set4)
print("\n")

# Checking relation between set3 and set4
if set3 > set4: # set3.issuperset(set4)
print("Set3 is superset of Set4")
elif set3 < set4: # set3.issubset(set4)
print("Set3 is subset of Set4")
else : # set3 == set4
print("Set3 is same as Set4")

# displaying relation between set4 and set3
if set4 < set3: # set4.issubset(set3)
print("Set4 is subset of Set3")
print("\n")

# difference between set3 and set4
set3 = set1 - set2
print("Elements in Set1 and not in Set2: Set3 = ", set3)
print("\n")

# checkv if set4 and set5 are disjoint sets
if set1.isdisjoint(set2):
print("Set1 and Set2 have nothing in common\n")

# Removing all the values of set5
set1.clear()

print("After applying clear on sets Set5: ")
print("Set1 = ", set1)
19 changes: 19 additions & 0 deletions #8_Python_Assignment_Compound_Operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Assignment operators in Python
# Operator Example Equivatent to
# = x = 5 x = 5
# += x += 5 x = x + 5
# -= x -= 5 x = x - 5
# *= x *= 5 x = x * 5
# /= x /= 5 x = x / 5
# %= x %= 5 x = x % 5
# //= x //= 5 x = x // 5
# **= x **= 5 x = x ** 5
# &= x &= 5 x = x & 5
# |= x |= 5 x = x | 5
# ^= x ^= 5 x = x ^ 5
# >>= x >>= 5 x = x >> 5
# <<= x <<= 5 x = x << 5

x=5
#output=a+
print ("a+ output is :",(x += 5),)