How to Get First and Last Character of String in Python?
Hey Developer,
This example is focused on python get first and last character of string. step by step explain how to get first and last character of string in python. Here you will learn get first and last character of string python. This article will give you a simple example of print first and last character of string in python. you will do the following things for extract first and last character from string in python.
In this examples, i will add myString variable with hello string. Then we will use key to getting first and last character from string in python. So, without further ado, let's see simple examples: You can use these examples with python3 (Python 3) version.
Example 1: Python Get First Character from String
main.py
# Declare String Variable myString = "Hello, This is ItSolutionStuff.com" # Getting First Character from String firstChar = myString[0] print(firstChar)
Output:
H
Example 2: Python Get Last Character from String
main.py
# Declare String Variable myString = "Hello, This is ItSolutionStuff.com" # Getting Last Character from String lastChar = myString[-1] print(lastChar)
Output:
m
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Python Remove First Character from String Example
- How to Get Last Character from String in Python?
- How to Get First Character from String in Python?
- How to Remove Last Word from String in Python?
- How to Remove First Word from String in Python?
- How to Get Last Word from String in Python?
- How to Get First Word from String in Python?
- Python PNG Image to Base64 String Example
- Python String Convert to Uppercase Example
- Python Split String into List of Characters Example
- How to Convert String into List in Python?
- Python Remove Empty String from List Example