Languages
[Edit]
EN

Python - get first character of string

0 points
Created by:
Dirask Community
6300

In this article, we would like to show you how to get the first character of a string in Python.

Quick solution:

first_character = string[0]

 

Practical example

In this example, we get the first character of "dirask" string by index.

Note:

In Python each character in a string has an index number associated with it. We can use the index to access any character.

Code:

string = "dirask"
first_character = string[0]
print("First character is:",first_character)

 Output:

First character is: d

See also

Python - string (popular problems)

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join