---
title: ord()
url: https://docs.vultr.com/python/built-in/ord
description: Convert Character to Integer
publish_date: 2024-09-27T17:05:20.859033Z
last_updated: 2024-09-27T17:05:20.859033Z
header_image: https://sjc1.vultrobjects.com/docs-main-doc-assets-1/collection-items/370/8f886384-d058-4900-8d04-0e0b15d88ae9.jpg
---

> Index of every Vultr Docs page in markdown: https://docs.vultr.com/llms.txt

# Python ord() - Convert Character to Integer

## Introduction
The `ord()` function in Python is essential for converting a single Unicode character into its corresponding Unicode point integer. This function plays a significant role in various applications, such as cryptographic algorithms, data parsing, and encoding processes where character manipulation at the integer level is required.

In this article, you will learn how to effectively use the `ord()` function in Python to handle character-to-integer conversions. Understand its behavior with different types of characters and explore some practical scenarios where `ord()` can be particularly useful.

## Basics of ord() Function

### Convert Basic English Characters
1. Choose a basic English character.
1. Pass the character as an argument to the `ord()` function.

    ```python
    char = 'A'
    unicode_point = ord(char)
    print(unicode_point)
    ```

    This code snippet will print the Unicode point of the character 'A', which is `65`. The `ord()` function simply converts the character to its corresponding integer, based on the Unicode standard.

### Handle Non-English Characters
1. Select a non-English text character.
1. Use the `ord()` function to convert this character to its Unicode integer.

    ```python
    char = 'é'
    unicode_point = ord(char)
    print(unicode_point)
    ```

    In this example, 'é' is converted into `233`. Non-English characters, including those with diacritical marks, have unique Unicode points which `ord()` can successfully retrieve.

## Advanced Usage Scenarios

### Using ord() in Cryptographic Conditions
1. Integrate `ord()` into a basic cryptographic function where each letter is shifted by a set number of places in the Unicode table.
1. Apply the function to encrypt a string.

    ```python
    def encrypt(text, shift):
        encrypted_text = ""
        for char in text:
            shifted = ord(char) + shift
            encrypted_text += chr(shifted)
        return encrypted_text
    
    sample_text = 'hello'
    encrypted = encrypt(sample_text, 2)
    print(encrypted)
    ```

    The `encrypt` function shifts each character in the input text by 2 Unicode points to create a simple encrypted string. This example reveals the straightforward integration of the `ord()` function in data encryption processes.

### Interaction with Other Functions
1. Combine `ord()` with `map()` to convert a whole string of characters to their respective Unicode integers.
1. Print the list of Unicode integers.

    ```python
    word = 'Python'
    unicode_points = list(map(ord, word))
    print(unicode_points)
    ```

    This code snippet will output the list of Unicode integers corresponding to each character in "Python". Using `map()` with `ord()` provides an efficient way to handle multiple conversions simultaneously.

## Conclusion
The `ord()` function is a powerful and simple tool in Python for converting characters into their corresponding Unicode integers. This function is invaluable for operations that require interaction with characters at their fundamental integer level, such as in encoding mechanisms, data transformation, and cryptographic applications. By mastering `ord()`, you can perform a wide range of tasks, from simple data manipulation to complex encryption algorithms, ensuring accurate and efficient data processing across different applications.