题解 | #字符个数统计#【熟悉方法:ASCII与字符转换】
字符个数统计
https://www.nowcoder.com/practice/eb94f6a5b2ba49c6ac72d40b5ce95f50
import sys x = input() y = x[0] for i in range(1, len(x)): if x[i] not in y and ord(x[i]) >= 0 and ord(x[i]) <= 127: y = y + x[i] else: pass print(len(y))
【目的】
python中用于将字符转换为ASCII的方法为:ord();
python中用于将ASCII转换为字符的方法为:char()。