Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ascii
uppercase
constant
python
communitycreator

What is the ascii_uppercase constant in Python?

abhilash

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The string module in Python

The string module in Python is a collection of different constants.

The ascii_uppercase constant

The ascii_uppercase constant in the string module contains the English letters from A to Z only in uppercase as a string.

The value of the constant is as follows:

ABCDEFGHIJKLMNOPQRSTUVWXYZ

Syntax

string.ascii_uppercase

As ascii_uppercase is a constant, we can access it via the string module name.

Code example 1

import string
ascii_uppercase_output = string.ascii_uppercase
print("string.ascii_uppercase = '%s'" % (ascii_uppercase_output))

Code explanation

  • Line 1: We import the string module.
  • Line 3: We store the output of string. ascii_uppercase in the ascii_uppercase_output variable.
  • Line 5: We print ascii_uppercase_output.

Code example 2

import string
def is_ascii_uppercase_only(str_input):
for i in str_input:
if i not in string.ascii_uppercase:
return False
return True
str_to_check_1 = "ADFVERFDD"
print("Does %s contains only ascii uppercase letters? %s" % (str_to_check_1, is_ascii_uppercase_only(str_to_check_1)))
str_to_check_2 = "abji232daosfdgfRFDFD"
print("Does %s contains only ascii uppercase letters? %s" % (str_to_check_2, is_ascii_uppercase_only(str_to_check_2)))

Code explanation

  • Line 1: We import the string module.
  • Lines 3–9: We define a method called is_ascii_uppercase_only that accepts a string as parameters and checks whether or not the input string contains only uppercase ASCII letters.
  • Line 11: We define a string called str_to_check_1 containing only ASCII uppercase letters.
  • Line 12: We invoke the is_ascii_uppercase_only method passing str_to_check_1 as a parameter. Then, we display the results.
  • Line 14: We define a string called str_to_check_2 containing lowercase and uppercase ASCII letters and digits.
  • Line 15: We invoke the is_ascii_uppercase_only method passing str_to_check_2 as a parameter. Then, we display the results.

RELATED TAGS

ascii
uppercase
constant
python
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring