print(ascii('Ù')) # '\xd9'
print(ascii('å')) # '\xe5'
print(ascii('õ')) # '\xf5'
print(ascii('÷')) # '\xf7'
Using string
print(ascii('þlûs2ñet'))
Output
'\xfel\xfbs2\xf1et'
Using List
my_list=['Oñe','Twö','Threë']
print(ascii(my_list))
Output
['O\xf1e', 'Tw\xf6', 'Thre\xeb']
Using for loop to display Unicode point value with equivalent char and printable char
for i in range(200,250):
print(i,":",chr(i),ascii(chr(i)))
print(ascii('Pythön is fun')) # 'Pyth\xf6n is fun'
my_list = ['Café', 'Niño']
print(ascii(my_list)) # ['Caf\xe9', 'Ni\xf1o']
my_tuple = ('naïve', 'façade')
print(ascii(my_tuple)) # ('na\xefve', 'fa\xe7ade')
my_dict = {'jalapeño': 'spicy', 'piñata': 'fun'}
print(ascii(my_dict)) # {'jalape\xf1o': 'spicy', 'pi\xf1ata': 'fun'}
my_set = {'résumé', 'cliché'}
print(ascii(my_set)) # {'r\xe9sum\xe9', 'clich\xe9'}
non_printable_str = 'Hello\u200bWorld' # Contains a zero-width space
print(ascii(non_printable_str)) # 'Hello\u200bWorld'
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.