Python program capitalize the character without using a function (2024)

  • Home
  • DS & Algo. ▾
    • Data Structure
    • Algorithms
    • Coding Problems
  • Languages ▾
    • C
    • C++
    • C++ STL
    • Java
    • Python
    • Scala
    • Ruby
    • C#.Net
    • Golang
    • Android
    • Kotlin
    • SQL
  • Web. ▾
    • JavaScript
    • CSS
    • jQuery
    • PHP
    • Node.Js
    • AdonisJs
    • VueJS
    • Ajax
    • HTML
    • Django
  • Programs ▾
    • C
    • C++
    • Data Structure
    • Java
    • C#.Net
    • VB.Net
    • Python
    • PHP
    • Golang
    • Scala
    • Swift
    • Rust
    • Ruby
    • Kotlin
    • C Interview Programs
  • Aptitude ▾
    • C Aptitude
    • C++ Aptitude
    • Java Aptitude
    • C# Aptitude
    • PHP Aptitude
    • Linux Aptitude
    • DBMS Aptitude
    • Networking Aptitude
    • AI Aptitude
    • More...
  • Interview ▾
    • Golang
    • MIS Executive
    • DBMS
    • C
    • Embedded C
    • Java
    • SEO
    • HR
  • Find Output ▾
    • C
    • C++
    • C#.Net
    • Java
    • Go
    • PHP
    • More...
  • MCQs ▾
    • Web Technologie MCQs
    • CS Subjects MCQs
    • Databases MCQs
    • Programming MCQs
    • Testing Software MCQs
    • Digital Mktg Subjects MCQs
    • Cloud Computing S/W MCQs
    • Engineering Subjects MCQs
    • Commerce MCQs
    • More MCQs...
  • CS Subjects ▾
    • Machine Learning/AI
    • Operating System
    • Computer Network
    • Software Engineering
    • Discrete Mathematics
    • Digital Electronics
    • Data Mining
    • MIS
    • DBMS
    • Embedded Systems
    • Cryptography
    • CS Fundamental
    • More Tutorials...
  • More ▾
    • Tech Articles
    • Puzzles
    • Full Forms
    • Code Examples
    • Blogs
    • Guest Post
    • Programmer's Calculator
    • XML Sitemap Generator
    • About
    • Contact

Home »Python »Python Programs

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 functionst = 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 Variables
  • Python Data Types
  • Python print() Method
  • Python input() Method
  • Python Conditional Statements
  • Python Loops

Python Basic Programs »

Python program to convert yards into meters

Python program to lowercase the character without using a function

Related Programs

  • Python | Find the factorial of a number using recursion
  • Python | Declare any variable without assigning any value.
  • Python | BMI (Body Mass Index) calculator.
  • Python | Program to print Odd and Even numbers from the list of integers.
  • Python | Program to print Palindrome numbers from the given list.
  • Python | Compute the net amount of a bank account based on the transactions.
  • Python | Count total number of bits in a number.
  • Python | Generate random number using numpy library.
  • Generate random integers between 0 and 9 in Python
  • Python | Program to calculate n-th term of a Fibonacci Series
  • Python program for sum of square of first N natural numbers
  • Python program for sum of cube of first N natural numbers
  • Python program to check prime number
  • Python program to find the largest prime factor of a number
  • Python program to find prime numbers using sieve of Eratosthenes
  • Python program to calculate prime numbers (using different algorithms) upto n
  • Python program to print all prime numbers in an interval
  • Python program to print all positive or negative numbers in a range
  • Python program for not None test
  • Python program for pass statement
  • Python program for Zip, Zap and Zoom game
  • Python program to convert temperature from Celsius to Fahrenheit and vice-versa
  • Python program to find the number of required bits to represent a number in O(1) complexity
  • Python program to count number of trailing zeros in Factorial of number N
  • Python program for swapping the value of two integers
  • Python program for swapping the value of two integers without third variable
  • Python program to find winner of the day
  • Python program for Tower of Hanoi
  • Python program to find standard deviation
  • Python program to find the variance
  • Python program Tower of Hanoi (modified)
  • Python program to convert Centimeter to Inches
  • Python program to convert meters into yards
  • Python program to convert yards into meters
  • Python program to lowercase the character without using a function
  • Python program to find perfect number
  • Python program to print perfect numbers from the given list of integers
  • Python program to find greatest integer using floor() method
  • Python program to find the maximum EVEN number
  • Python program to find the maximum ODD number
  • Python program to find the solution of a special sum series
  • Python | Convert the binary number to decimal without using library function
  • Python | Convert the decimal number to binary without using library function
  • Create a stopwatch using Python
  • Python program to find the maximum multiple from given N numbers
  • Python program to find the least multiple from given N numbers
  • Find the root of the quadratic equation in Python
  • Python program to check the given Date is valid or not
  • Python program to print the calendar of any year

Comments and Discussions!

Load comments ↻


Python program capitalize the character without using a function (2024)

FAQs

How to capitalize string in Python without inbuilt function? ›

Split the string into a list of words using the split() method. Use a list comprehension to capitalize the first letter of each word using the upper() method. Join the capitalized words back together using the join() method with a space as the separator. Print the final result.

How do you capitalize a character in Python? ›

Using the upper() method will capitalize the first character in a string, and the lower() method will convert the rest to lowercase.

How to convert string to uppercase without using inbuilt function? ›

Just get the ascii code for each char, and if it ranges between 97 to 122 ( a to z ) deduct 32 from val to get the corresponding upper case char. Hope this helps. As Barmar mentioned in the comments above: Subtract 32 from the character code if the character is between 97 and 123.

How to capitalize string in Python? ›

Python upper() – The Python upper() method returns a string that has all lowercase characters converted to uppercase characters. Python capitalize() – The capitalize() function in Python turns the first character of a string to an uppercase letter and lowercases any remaining characters.

How do you force a string to uppercase in Python? ›

Python upper() function is an inbuilt string class method that converts all the lowercase characters in the string into uppercase characters and returns a new string. The Python upper() string method returns a string copy with all the characters changed to uppercase.

How do you capitalize an element in Python? ›

String capitalize() Method in Python. Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter while making all other characters in the string lowercase letters.

How do you input capital letters in Python? ›

capitalize() in Python is used to convert the first character of a string to uppercase and the remaining characters to lowercase. The capitalize() function takes no parameters. capitalize() does not modify the actual input string but returns a new updated string.

How to convert a specific character in a string to uppercase in Python? ›

Method #1 : Using string slicing + upper()

This task can easily be performed using the upper method which uppercases the characters provided to it and slicing can be used to add the remaining string after the uppercase Nth character.

How to convert a character into uppercase? ›

To convert a character to uppercase by using the casing conventions of the current culture, call the ToUpper(Char, CultureInfo) method overload with a value of CurrentCulture for its culture parameter.

How do you convert letters to uppercase in Python? ›

To convert a string to uppercase in Python, you can use the upper() function, such as print(text. upper()) , where text is a string variable. This function is a built-in method in Python that can be used on any string object to convert all the characters to uppercase. In this example, we have a string 'hello world'.

How do I convert an entire string to uppercase? ›

Use string. upper() to convert a string to uppercase, and string. lower() to convert a string to lowercase.

How to count in Python without function? ›

Python Program to Calculate the Length of a String Without using Library Functions
  1. Take a string from the user and store it in a variable.
  2. Initialize a count variable to 0.
  3. Use a for loop to traverse through the characters in the string and increment the count variable each time.
  4. Print the total count of the variable.

What does len do in Python? ›

Definition and Usage

The len() function returns the number of items in an object. When the object is a string, the len() function returns the number of characters in the string.

How to count letters in string in Python? ›

How do you count characters in Python? To count specific characters in a string in Python, we use the string count() function. We specify the character as a substring parameter in the count() function. Also, we need to keep In mind that Python string count() accepts only a single substring parameter.

How to remove a character from a string in Python without inbuilt function? ›

These are the following methods using which we can remove letters from a string in Python:
  1. Using str.replace()
  2. Using translate()
  3. Using recursion.
  4. Using Native Method.
  5. Using slice + concatenation.
  6. Using str.join()
  7. Using bytearray.
  8. Using removeprefix()
Aug 28, 2023

How do I get only capital letters from a string in Python? ›

Let's discuss certain ways in which only uppercase letters can be extracted from a string. List comprehension and isupper function can be used to perform this particular task. The list comprehension is primarily used to iterate over the list and isupper function checks for the uppercase characters.

How to convert string lowercase to uppercase in Python? ›

To convert a string to uppercase in Python, you can use the upper() function, such as print(text. upper()) , where text is a string variable. This function is a built-in method in Python that can be used on any string object to convert all the characters to uppercase. In this example, we have a string 'hello world'.

References

Top Articles
Latest Posts
Article information

Author: Prof. Nancy Dach

Last Updated:

Views: 6022

Rating: 4.7 / 5 (77 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Prof. Nancy Dach

Birthday: 1993-08-23

Address: 569 Waelchi Ports, South Blainebury, LA 11589

Phone: +9958996486049

Job: Sales Manager

Hobby: Web surfing, Scuba diving, Mountaineering, Writing, Sailing, Dance, Blacksmithing

Introduction: My name is Prof. Nancy Dach, I am a lively, joyous, courageous, lovely, tender, charming, open person who loves writing and wants to share my knowledge and understanding with you.