您如何将全名格式化为首字母缩写? (X.X.X。)

How could you format a full name into just initials? (X.X.X.)

我正在尝试将全名转换为一个字符串中的首字母。我的逻辑是将字符串中的所有名称都大写,用空格将字符串分成一个列表,然后 select 每个索引的第一个字符,然后将字符连接成一个由句点分隔的字符串。

我遇到了这个问题,不确定是否有更好的方法。

这是我目前的进度:

def main():
    fstn= input("Enter your full name:")

    fstn=fstn.title()
    fstn= fstn.split(" ")
    for i in fstn:
        fstn= i[0]
        print(fstn)


main()

这会在不同的行上打印出每个首字母,我将如何完成它?

你好,看看这个例子,

def main():
    fstn= input("Enter your full name:")
    fstn=fstn.title()
    fstn= fstn.split(" ")
    out_str = ""
    for i in fstn:
        out_str = out_str + i[0] + "."
    print(out_str)

main()
def main():
    fstn= input("Enter your full name:")
    print ('.'.join(word[0] for word in fstn.split(" ")).upper()) #for python 3


main()