Python program to find hash of a string














































Python program to find hash of a string



 DESCRIPTION: The hash() method returns the hash value of an object if it exists. The hash() method only works for   immutable objects as tuple. Example: 'Python'.
 Hash values are just integers which are used to compare dictionary keys   during a dictionary lookup quickly. Internally,   hash() method calls __hash__() method of an object which are set by   default for any object. The syntax of a hash   method is:- 
 hash(object)
 
class Hash:
    #Run the constructor for class
    def __init__(self, string):

        #Initialize the variables
        self.string = string

    #hash() method is used to find the hash
    def find_hash(self):
        return hash(self.string)

def main():
    string = input("Enter the string: ")
    #object for class Hash
    obj_Hash = Hash(string)
    print("The hash of string is: ", obj_Hash.find_hash())
    

#Driver code
if __name__ == "__main__":
    main()

OUTPUT:
Testcase1:
Enter the string: 'cppsecrets'
The hash of string is: 8383812578227545840

Testcase2:
Enter the string: 156
The hash of string is:  4131132952895431652

Testcase3:
Enter the string: 195.26
The hash of string is:  3220936346547828279

More Articles of Anjani Dubey:

Name Views Likes
Python program to check if a Binary tree is height balanced or not 901 16
Python program to convert BST into MinHeap 447 18
Python program to delete an element into AVL Tree 870 19
Python program to insert an element in AVL Tree 473 27
Python program to delete an element in Binary search tree 442 18
Python program to insert and find an element in Binary Search Tree 513 18
Python program to insert an element in the Binary Tree 761 18
Python program to find height of the Binary Search Tree(BST) 574 11
Python program to combine two sorted lists and make another sorted list 418 16
Python program to convert multiple integers into single integer 727 22
Python program to convert Nested list into a flat list 526 17
Python program to convert tuple to a string 601 26
Python program for traversing the Tree in PreOrder, PostOrder and InOrder 741 13
Python program to find hash of a string 379 28
Python program for Counting sort Algorithm 307 13
Python program for Insertion sort Algorithm 499 23
Python program for Bubble Sort algorithm 384 12
Python program for UNIX domain socket UDP client 341 15
Python UNIX domain socket UDP server 422 24
Python program for Binary Search Tree 438 20
Python UNIX domain socket TCP Client 316 16
Python UNIX domain socket TCP Server 383 16
Python program to convert POS to SOP 341 15
Advantages of UNIX domain socket over Normal sockets 628 24
Python program for Merge Sort Algorithm 382 21
Python program to print duplicate characters and count from a string 1535 20
Python program to find all pairs of an integer array whose sum is equal to a given number 1192 18
Python program to find all Permutations of a string 347 11
Python program to reverse the string using recursion 444 15
Python program to check two strings are anagrams of each other 712 22
Python program to convert Hexadecimal to Decimal, Binary, Octal 1762 27
Python program to convert Octal to Decimal, Binary, Hexadecimal 1849 28
Python program to Shuffle deck of cards 907 18
Python program for One Dimensional Array 333 23
Python program to merge mails 334 19
Python program to display powers of 2 380 20
Python program to find numbers Divisible by Another number 1007 24
Python program to print strings 297 14
Python program to find Average of numbers 307 23
Python program to find the solutions for a Quadratic equation 772 18
Python program to generate Armstrong numbers for a specific range 253 17
Python program to calculate perimeter of Triangle 379 23
Python program to calculate perimeter of a Rectangle 303 18
Python program to calculate the factors of a number 255 11
Python program to calculate the Square root of a number 478 19
Python program to calculate the area of Rectangle 322 17
Python program to print the Floyd Triangle 278 15
Python program to find the sum of natural number using Recursion 326 17
Python program to find the Fibonacci sequence recursion 426 30
Python Program to check whether a number is Palindrome or not 498 11
Program to check whether a number is Palindrome or not 456 17
Program to find average of numbers 318 16
Program to solve the Quadratic Equation 358 19
Program to generate the Armstrong numbers for a specific range 307 21
Program to calculate the perimeter of triangle 342 22
Program to calculate the perimeter of rectangle 479 14
Program to Display the Fibonacci series using Recursion 241 14
Program to find factors of a number 275 18
Program to calculate Square root of a number 244 18
Program to calculate area of Rectangle 303 25
Python Program for calculating the Area of Triangle 294 22
Program to print the Floyd Triangle 268 20
Python Program to calculate the Grade of the Student 5961 21
Program to calculate sum of natural numbers using Recursion 254 18

Comments