简体   繁体   English

有没有办法在没有索引的情况下打印特定的字符串字母?

[英]Is there any way to print a specific letter of string without indexing?

Write a Python program that reads a line from the user and prints the first character of the given input.编写一个 Python 程序,从用户那里读取一行并打印给定输入的第一个字符。

Sample Input样本输入 Sample Output示例输出
The quick brown fox jumps over the lazy dog敏捷的棕色狐狸跳过了懒狗 T
Python is an interpreted language Python 是一种解释型语言 P P
N=('Python is an interpreted language ')
Print(N[0])

I guess you could我想你可以

print(next(iter(N)))

It creates an iterator from string N. And next(it) gives the next element in the iteration, which, the first time, is the first element.它从字符串 N 创建一个迭代器。 next(it)给出迭代中的下一个元素,第一次是第一个元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何询问字符串,然后询问字符串的位置,然后删除字母并打印没有字母的单词 - How to ask for a string, then ask for a position of string, then remove the letter and print the word without the letter 检查字符串是否包含任意数量的数字后跟特定字母[Python] - Check if a string contains any amount of numbers followed by a specific letter [Python] 尝试检索特定字母时出现索引错误 - Indexing error while trying to retrieve specific letter 有没有办法使用切片和索引来检索特定的字符串值? - Is there a way to retrieve specific string values using slicing and indexing? 字符串中特定字母的数量 - Number of specific letter in string 有什么方法可以在不使用 Python 中的任何字符串或数字的情况下打印某些内容? - Is there any way to print something without using any strings or numbers in Python? 在 tkinter 中逐个字母地写文本的任何方式 - any way to write text letter by letter in tkinter 在打印字符串中打印希腊字母 - Print Greek letter in printed string 有没有办法可以使用'if'函数根据原始输入字符串的第一个字母打印出一个字符串? - Is there a way I can use the 'if' function to print out a string depending on the first letter of the original input string? Python:使用特定条件索引字符串 - Python: Indexing a string with specific conditions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM