0

How to find the first letter of a input string

I tried this : x = input() print(x[1])

25th May 2020, 4:19 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
7 Answers
+ 7
Python uses 0-based indexing. print(x[0])
25th May 2020, 4:21 PM
Hatsy Rei
Hatsy Rei - avatar
+ 6
This also will do the job: print(input()[0])
25th May 2020, 5:18 PM
Lothar
Lothar - avatar
+ 2
Hey hey here counting starts from 0 not 1 🤘
25th May 2020, 8:51 PM
Mehnaz ✨
Mehnaz ✨ - avatar
+ 1
In python indexes start at 0. It should be x[0]
25th May 2020, 4:21 PM
Ore
Ore - avatar
0
Thanks
25th May 2020, 4:21 PM
Gurseerit Singh Chahal ✓
Gurseerit Singh Chahal ✓ - avatar
0
the regex here is ^\w where the ^ indicates to look if it happens at the start of the string and then the \w is for any a-z, A-Z, and _
25th May 2020, 4:22 PM
Killian Fortman
Killian Fortman - avatar
- 1
look into regex. I use regex to do this stuff. something like import re x = input(“”) y = re.findall(“^\w”, x) print(y)
25th May 2020, 4:21 PM
Killian Fortman
Killian Fortman - avatar