879282. Print ascii value in python

Easy

Print ascii value in python

Summary

The problem requires printing ASCII values for a given input string. The key concept involved is the use of ASCII codes, which represent characters as unique numerical values.

Detailed Explanation

To solve this problem, we can iterate through each character in the input string and print its corresponding ASCII value. We can do this by using Python's built-in ord() function, which returns the Unicode code point for a given character.

Here is the step-by-step breakdown of the solution:

  1. Initialize an empty string to store the output.
  2. Iterate through each character in the input string.
  3. For each character, use the ord() function to get its ASCII value.
  4. Append the ASCII value as a string to the output string.
  5. Print the final output string.

Here is the time and space complexity analysis:

  • Time complexity: O(n), where n is the length of the input string.
  • Space complexity: O(n), where n is the length of the output string.

Optimized Solutions

Python

python
def print_ascii(input_string):
    output = ""
    for char in input_string:
        output += str(ord(char)) + " "
    print(output)

# Test the function
input_string = "Hello World"
print_ascii(input_string)
View on GeeksforGeeks

Not available

DevExCode

Master coding interviews with Leetcode, system design, TechBit, QuickLearn, DevTips, Tech Battles, and career services.

© 2026 DevExCode. All rights reserved.