Recommended Free Tools
For a non-empty Python string s, use s[0]. Python sequences start at index 0, so this returns the first element as a one-character str.
Get the first character with s[0]
s = "Python"
first = s[0] # "P"
Python strings are indexed from zero: index 0 is the first element, index 1 is the second, and so on. Because Python has no separate character type, indexing a string returns another string of length one. The Python built-in types reference documents that, for a non-empty string, s[0] is equivalent to s[0:1].
As an Amazon Associate I earn from qualifying purchases.
What if the string might be empty?
Indexing an empty string at 0 raises IndexError, because there is no element at that position. Choose the operation that matches the function’s contract:
| Expression | Non-empty string | Empty string | Use when |
|---|---|---|---|
s[0] |
Returns the first character as a one-character str |
Raises IndexError |
An empty string is invalid and should be handled explicitly |
s[:1] |
Returns the first character as a one-character str |
Returns "" |
An empty result is acceptable |
For example, a slice provides an empty-safe result:
#1 Best Overall
s = ""
first_or_empty = s[:1] # ""
If an empty value is an error in your application, check for it and raise or handle a clear application-specific error rather than silently returning an empty string.
Does the first element always match one visible character?
Not necessarily. Python str values are immutable sequences of Unicode code points, and s[0] returns one code point. A symbol that appears as a single character on screen can consist of multiple code points, so indexing may return only part of what a person perceives as one character. If an interface must split text into user-perceived characters, use grapheme-aware Unicode processing instead of assuming that s[0] is a complete visual character.
Rank #2
What if the value is bytes?
bytes represents binary data, not decoded text. Its indexing does not return a text str character. Decode the bytes with the correct encoding first, then index the resulting string. Calling str(b"...") without encoding arguments produces the bytes object’s representation; it does not decode the data. See the Python built-in types reference for the distinction.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




