×

Python Tutorial

Python Basics

Python I/O

Python Operators

Python Conditions & Controls

Python Functions

Python Strings

Python Modules

Python Lists

Python OOPs

Python Arrays

Python Dictionary

Python Sets

Python Tuples

Python Exception Handling

Python NumPy

Python Pandas

Python File Handling

Python WebSocket

Python GUI Programming

Python Image Processing

Python Miscellaneous

Python Practice

Python Programs

Python program capitalize the character without using a function

Capitalize the character: Here, we are going to learn how to capitalize the character without using a function in Python? By Anuj Singh Last updated : January 04, 2024

Problem statement

In this article, we will go for capitalizing the characters i.e. conversion from lowercase to uppercase without using any function. This article is based on the concept that how inbuilt function perform this task for us?

So, let's write a program to perform this task.

Key: The difference between the ASCII value of A and a is 32

Example

Consider the below example with sample input and output:

Input:
Hello world!

Output:
HELLO WORLD!

Python code to capitalize the character without using a function

# Python program to capitalize the character 
# without using a function
st = input('Type a string: ')
out = ''
for n in st:
    if n not in 'abcdefghijklmnopqrstuvwqxyz':
        out = out + n
    else:
        k = ord(n)
        l = k - 32
        out = out + chr(l)
print('------->', out)    

Output

First run:
Type a string: Hello world!
-------> HELLO WORLD!

Second run:
Type a string: 12345Hello @123$#
-------> 12345HELLO @123$#

Third run:
Type a string: 82918298198291898A
-------> 82918298198291898A

To understand the above program, you should have the basic knowledge of the following Python topics:

Python Basic Programs »

Advertisement
Advertisement

Related Programs

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.