1.
int->char & char ->int
int->char & char ->int
chr
(i)¶
Return the string representing a character whose Unicode code point is the integer i. For example, chr(97)
returns the string 'a'
, while chr(8364)
returns the string '€'
. This is the inverse of ord()
.
The valid range for the argument is from 0 through 1,114,111 (0x10FFFF in base 16).
ValueError
will be raised if i is outside that range.
ord
(c)
Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. For example,
2.Reverse a str in python
ord('a')
returns the integer 97
and ord('€')
(Euro sign) returns 8364
. This is the inverse of chr()
.2.Reverse a str in python
How about:
>>> 'hello world'[::-1]
'dlrow olleh'
This is extended slice syntax. It works by doing [begin:end:step]
- by leaving begin and end off and specifying a step of -1, it reverses a string.
''.join(reversed(s))
.