xlabel位置 - Python:如何打印范围az?




python title位置 (9)

1.打印一个: abcdefghijklmn

2.每一秒钟: acegikm

3.附加到URL的索引{ hello.com/,hej.com/,...,hallo.com/}:hello.com/a hej.com/b ... hallo.com/n


获取包含所需值的列表

small_letters = map(chr, range(ord('a'), ord('z')+1))
big_letters = map(chr, range(ord('A'), ord('Z')+1))
digits = map(chr, range(ord('0'), ord('9')+1))

要么

import string
string.letters
string.uppercase
string.digits

此解决方案使用ASCII表ord从字符中获取ascii值,反之亦然。

应用您对列表的了解

>>> small_letters = map(chr, range(ord('a'), ord('z')+1))

>>> an = small_letters[0:(ord('n')-ord('a')+1)]
>>> print(" ".join(an))
a b c d e f g h i j k l m n

>>> print(" ".join(small_letters[0::2]))
a c e g i k m o q s u w y

>>> s = small_letters[0:(ord('n')-ord('a')+1):2]
>>> print(" ".join(s))
a c e g i k m

>>> urls = ["hello.com/", "hej.com/", "hallo.com/"]
>>> print([x + y for x, y in zip(urls, an)])
['hello.com/a', 'hej.com/b', 'hallo.com/c']

假设这是一个家庭作业;-) - 不需要召唤库等 - 它可能希望你使用chr / ord的range(),如下所示:

for i in range(ord('a'), ord('n')+1):
    print chr(i),

其余的,只需使用范围()玩一点


尝试:

strng = ""
for i in range(97,123):
    strng = strng + chr(i)
print(strng)

提示:

import string
print string.ascii_lowercase

for i in xrange(0, 10, 2):
    print i

"hello{0}, world!".format('z')

这是你的第二个问题: string.lowercase[ord('a')-97:ord('n')-97:2]因为97==ord('a') - 如果你想学习一点你应该自己弄明白;-)


#1)
print " ".join(map(chr, range(ord('a'),ord('n')+1)))

#2)
print " ".join(map(chr, range(ord('a'),ord('n')+1,2)))

#3)
urls = ["hello.com/", "hej.com/", "hallo.com/"]
an = map(chr, range(ord('a'),ord('n')+1))
print [ x + y for x,y in zip(urls, an)]

for one in range(97,110):
    print chr(one)

import string
print list(string.ascii_lowercase)
# ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

list(string.ascii_lowercase)

['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']






ascii