Python Programs | IT Developer
IT Developer

Python Programs



Share with a Friend

Python Programs - String

Find ASCII value of each character - Python Program

Example 1 :

text = "AB" for ch in text: print(f"{ch}: {ord(ch)}")

Output

 
OUTPUT  :
A: 65
B: 66

Example 2 :

# Get input from the user char = input("Enter a character: ") # Check if the input is a single character if len(char) == 1: # Use the ord() function to get the ASCII value ascii_value = ord(char) print(f"The ASCII value of '{char}' is: {ascii_value}") else: print("Please enter a single character.")

Output

 
OUTPUT  :
Enter a character: A
The ASCII value of 'A' is: 65