[英]How to get python to display the first letter from input
For example, if I entered "Harry Potter"
into the following code.例如,如果我在以下代码中输入
"Harry Potter"
。 What should I write in the blank spaces so that First_letter
will be assigned with H
, Second_letter
with a
, etc.我应该在空格中写什么,以便
First_letter
将被分配为H
, Second_letter
与a
等。
If possible, please also explain how the code works.如果可能,还请解释代码的工作原理。
Any help will be greatly appreciated!任何帮助将不胜感激!
Name = input("Enter your name")
First_letter = ____
Second_letter = ____
Third_letter = ____
You could use index for str
objects:您可以对
str
对象使用索引:
Name = input("Enter your name")
First_letter = Name[0]
Second_letter = Name[1]
Third_letter = Name[2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.