Letter digit or special character in python assignment expert

Letter, Digit or Special Character

You are given a character as input. Check if the given input is a Lowercase Letter or Uppercase Letter or Digit or a Special Character.

Input

The first line of input is a single character N.

Explanation

In the given example character is

9. So, the output should be Digit.

Sample Input 1

9

Sample Output 1

Digit

Sample Input 2

A

Sample Output 2

Uppercase Letter

Hello and welcome, in this post we will explore all the methods of Python strings that are used for case conversion in Python assignment experts. We will see how to use them with one example of each.

Nội dung chính

  • 4. capitalize()
  • 5. swapcase()
  • 6. center()
  • 7. casefold()
  • How do you make the first character uppercase in Python?
  • How do you code uppercase in Python?
  • How do you capitalize the first and last letter in Python?

1. lower()

Converts every character of the string to lowercase.

my_str = "A STRING"
my_str = my_str.lower()
print(my_str)

Output:

a string

2. upper()

Converts every character of the string to uppercase.

my_str = "a string"
my_str = my_str.upper()
print(my_str)

Output:

A STRING

3. title()

Converts the first character of each word to upper case.

my_str = "a string"
my_str = my_str.title()
print(my_str)

Output:

A String

4. capitalize()

Converts the first character to the upper case.

my_str = "a string"
my_str = my_str.capitalize()
print(my_str)

Output:

A string

5. swapcase()

Swaps cases, the lower case becomes the upper case, and vice versa.

my_lower_str = "a string"
my_upper_str = "A STRING"
my_str_1 = my_lower_str.swapcase()
my_str_2 = my_upper_str.swapcase()
print(my_str_1)
print(my_str_2)

Output:

A STRING
a string

6. center()

Returns a centered string.

my_str = "a string"
my_str = my_str.center(20, "-")
print(my_str)

Output:

------a string------

7. casefold()

Converts string into lower case.

my_str = "a sTRINg"
my_str = my_str.casefold()
print(my_str)

Output:

a string

Conclusion

We hope this article on Case conversion in python assignment expert will help you to learn how to use case conversion methods of a string in Python to convert a string from one case to another.

Thank you for visiting our website.


Also Read:

  • Split the sentence in Python | Assignment Expert
  • String Slicing in JavaScript | Assignment Expert
  • First and Last Digits in Python | Assignment Expert
  • List Indexing in Python | Assignment Expert
  • Date Format in Python | Assignment Expert
  • New Year Countdown in Python | Assignment Expert
  • Add Two Polynomials in Python | Assignment Expert
  • Sum of even numbers in Python | Assignment Expert
  • Evens and Odds in Python | Assignment Expert
  • A Game of Letters in Python | Assignment Expert
  • Sum of non-primes in Python | Assignment Expert
  • Smallest Missing Number in Python | Assignment Expert
  • String Rotation in Python | Assignment Expert
  • Secret Message in Python | Assignment Expert
  • Word Mix in Python | Assignment Expert
  • Single Digit Number in Python | Assignment Expert
  • Shift Numbers in Python | Assignment Expert
  • Weekend in Python | Assignment Expert
  • Shift Numbers in Python | Assignment Expert
  • Temperature Conversion in Python | Assignment Expert
  • Special Characters in Python | Assignment Expert
  • Sum of Prime Numbers in the Input in Python | Assignment Expert
  • Numbers in String-1 in Python | Assignment Expert
  • Replace Elements with Zeros in Python | Assignment Expert
  • Remove Words in Python | Assignment Expert
  • Sum of n numbers in Python using for loop
  • Print Digit 9 in Python | Assignment Expert
  • First Prime Number in Python | Assignment Expert
  • Simple Calculator in Python | Assignment Expert
  • Average of Given Numbers in Python | Assignment Expert

Letter, Digit or Special Character

You are given a character as input. Check if the given input is a Lowercase Letter or Uppercase Letter or Digit or a Special Character.

Input

The first line of input is a single character N.

Explanation

In the given example character is

9. So, the output should be Digit.

Sample Input 1

9

Sample Output 1

Digit

Sample Input 2

A

Sample Output 2

Uppercase Letter

How do you make the first character uppercase in Python?

string capitalize() 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 code uppercase in Python?

upper() method returns the uppercase string from the given string. It converts all lowercase characters to uppercase. If no lowercase characters exist, it returns the original string.

How do you capitalize the first and last letter in Python?

2 comments on “Python program to capitalize the first and last letter of each word of a string”.

BHANU. a=input() print(a[0].upper()+a[1:len(a)-1]+a[len(a)-1].upper()) ... .

yaminipolisetti98435. s=input() n=len(s) print(s[0].upper()+s[1:n-1]+s[-1].upper()).