-1

For example, if I had the string thisisastring how could I find the first character? Is there an easy way to do this? Thank you!

smci
  • 32,567
  • 20
  • 113
  • 146
Alex
  • 21
  • 1
  • 1
  • Do you mean how to get 't' from 'thisisastring'? – Vitalii Strimbanu Oct 27 '16 at 20:14
  • @Robbie, it's not really a duplicate. `s[0]` and `s[:3]` are different. – smci Oct 28 '16 at 01:01
  • @smci Probably not the best "duplicate" example to use, but it's there plenty of times where, with a minimal amount of searching here (or googling) the answer would appear or could easily be deduced. – Robbie Oct 28 '16 at 01:34
  • @Robbie: I'm saying that surprisingly and shockingly, there is no canonical existing answer for the actual question "How do I find the first letter of a string? in Python". (There's lots of other stuff which implicitly includes it.) So if there isn't any canonical question, this one will and should become the canonical answer. – smci Oct 28 '16 at 04:15
  • @smci: Fair enough. I'll remove the close vote. – Robbie Oct 28 '16 at 04:26

1 Answers1

2

This will help you:

string = "thisisastring"
print(string[0])

# output: t

More on this topic in the String documentation.

kame
  • 20,848
  • 33
  • 104
  • 159
  • 2
    i think it would be good idea to suggest @Alex to check official [string documentaion](https://docs.python.org/2/library/string.html) – Vitalii Strimbanu Oct 27 '16 at 20:18