作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将全名转换为一个字符串的首字母缩写。我的逻辑是将字符串中的所有名称大写,将字符串按空格分成一个列表,然后选择每个索引的第一个字符,然后将字符连接成一个用句点分隔的字符串。
我在这方面遇到了麻烦,不确定是否有更好的方法。
这是我当前的进度:
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:")
print ('.'.join(word[0] for word in fstn.split(" ")).upper()) #for python 3
main()
关于python - 如何将全名格式化为首字母缩写? (X.X.X.),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46733638/
我是一名优秀的程序员,十分优秀!