Python ord()

C++: Python ord() Function

#include <iostream>

int main() {
    char c = 'A';
    int result = int(c);
    std::cout << "The ASCII value of " << c << " is " << result;
    return 0;
}

Python ord() Function Explanation

# Using the ord() function to get the ASCII value of a character
char = 'A'  # Define a character
result = ord(char)  # Use the ord() function to get the ASCII value
print(f"The ASCII value of {char} is {result}")  # Print the result

In this example, we demonstrate how to obtain the ASCII value of a character using the ord() function in Python. The ord() function returns the Unicode code point for a given character. In C++, we achieve a similar result by casting the character to an integer, which yields its ASCII value.