Sitemap

Python Engine String Data Type

11 min readAug 22, 2026

--

Press enter or click to view image in full size
Pyhton String data types

Python String Data Type: upper() Method

A string is a sequence of characters used to store text in Python. Strings can contain letters, numbers, spaces, and symbols. They are written inside single (' ') or double (" ") quotation marks.

The upper() method is used to convert all lowercase letters in a string to uppercase letters.

Syntax

string_name.upper()

Example

course_name = "Python Engine"
uppercase_name = course_name.upper()print("Original String:", course_name)
print("Uppercase String:", uppercase_name)

Output

Original String: Python Engine
Uppercase String: PYTHON ENGINE

Explanation

  • course_name stores the text "Python Engine".
  • course_name.upper() converts every alphabetic character to uppercase.
  • The original string remains unchanged because Python strings are immutable.
  • The converted value is stored in a new variable called uppercase_name

Example with Numbers and Symbols

message = "Welcome to Python 3.14!"
print(message.upper())

Output

WELCOME TO PYTHON 3.14!

The upper() method changes letters only. Numbers, spaces, and symbols remain unchanged.

Python String Data Type: lower() Method

The lower() method converts all uppercase letters in a string into lowercase letters.

Syntax

string_name.lower()

Example

course_name = "PYTHON ENGINE"
lowercase_name = course_name.lower()print("Original String:", course_name)
print("Lowercase String:", lowercase_name)

Output

Original String: PYTHON ENGINE
Lowercase String: python engine

Explanation

  • course_name contains uppercase text.
  • course_name.lower() converts every alphabetic character to lowercase.
  • Python strings are immutable, so the original value does not change.
  • The result is stored in the new variable lowercase_name.:

Example with Numbers and Symbols

message = "WELCOME TO Python 3.14!"
print(message.lower())

Output

welcome to python 3.14!

Numbers, spaces, and symbols are not affected by the lower() method.

3. Python String Data Type: swapcase() Method

The swapcase() method is used to change uppercase letters to lowercase letters and lowercase letters to uppercase letters. This is called swapping the letter case.

Example:

var = "pYTHON "
result = var.swapcase()
print(result)

Output:

Python

4. Python String Data Type: capitalize() Method

The capitalize() method converts the first character of a string to uppercase and changes all remaining characters to lowercase.

var = "python was created by guido van rossum in 1991"
result = var.capitalize()print(result)

Output:

Python was created by guido van rossum in 1991


Press enter or click to view image in full size

5. PYTHON STRING DATA TYPE: TITLE( ) METHOD

The title() method in Python is used with strings. It changes the first letter of every word to an uppercase letter and converts the remaining letters to lowercase.

Example:

var = "python was case sensitive live language"
print(var.title())

Output:

Python Was Case Sensitive Live Language

title() treats digits and symbols as word separators, so the next letter becomes uppercase.

6. count() Method

In Python, the count() method is used with strings to find how many times a specified letter, word, or group of characters appears. You can also choose the starting and ending positions for the search.

Example:

var1 = "python engine"
result = var1.count("engine")print(result)

Output:

1

You can also search within a specific part of the string:

var1 = "python engine"
result = var1.count("engine", 2, 13)print(result)

Output:

1

7. REPLACE ( ) METHOD

In Python, the replace() method replaces a word or part of a string with another word or string.

Example:

var = "python"
result = var.replace("python", "Python Engine")print(result)

Output:

Python Engine

You can also replace a specific part of a word using the replace() method.

var = "python Engine"
result = var.replace("En", "en", 2)print(result)

Output:

python engine

Here, "En" is replaced with "en". The number 2 means Python can replace up to two occurrences.

8. index() Method

In Python, the index() method is used to find the position of a letter, word, or group of characters in a string. It returns the position where the specified value first appears.

Example:

var = "python engine"
result = var.index("engine")print(result)

Output:

7

Python starts counting positions from 0. If the specified value is not found, index() produces an error.

9. FIND ( ) METHOD

In Python, the find() method is used to find the position of a letter, word, or group of characters in a string. It is similar to the index() method.

The difference is that if the value is not found, find() returns -1 instead of showing an error.

Example:

var = "python engine"
result = var.find("Engine")print(result)

Output:

-1

Python is case-sensitive, so "Engine" and "engine" are different.

You can also find a word that exists in the string:

var = "python engine"
print(var.find("engine"))

Output:

7

10. strip() Method

In Python, the strip() method removes extra spaces or specified characters from the beginning and end of a string. It does not remove spaces or characters from the middle of the string.

Example:

var = "  Python was created by Guido van Rossum  "
result = var.strip()print(result)

Output:

Python was created by Guido van Rossum

The spaces at the left and right sides of the string are removed.

You can also use strip() to remove specific characters from both ends of a string.

var = "enpython engineen"
result = var.strip("en")print(result)

Output:

python engi

Here, strip("en") removes e and n characters only from the beginning and end. It does not remove them from the middle, and it does not create a list.

11. lstrip() Method

In Python, the lstrip() method removes spaces or specified characters from the left side (beginning) of a string. It does not change the original string, so store the result in a variable or print it directly.

Example:

var = "python"
result = var.lstrip("py")print(result)

Output:

thon

Here, lstrip("py") removes the characters p and y from the beginning of "python".

To remove only left-side spaces:

var = "  python"
print(var.lstrip())

Output:

python

12. rstrip() Method

In Python, the rstrip() method removes spaces or specified characters from the right side (end) of a string. It does not remove characters from the beginning or middle of the string.

Example:

var = "python engine"
result = var.rstrip("e")print(result)

Output:

python engin

Here, rstrip("e") removes the letter e from the end of the string.

Get Kumarbsai’s stories in your inbox

Join Medium for free to get updates from this writer.

To remove only spaces from the right side:

var = "python engine   "
print(var.rstrip())

Output:

python engine

13. rfind() Methods

The find() method finds the first occurrence of text from the left side of a string. The rfind() method finds the last occurrence from the right side.

var = "Hyderabad der"
print(var.find("der"))
print(var.rfind("der"))

Output:

2
10

If the text is not found, both methods return -1.

14. rindex() Method

In Python, the rindex() method finds the position of a letter, word, or group of characters from the right side of a string. It returns the position of the last occurrence.

var = "right index"
result = var.rindex("ex")print(result)

Output:

9

If the specified text is not found, rindex() shows an error. Use rfind() instead if you want -1 when the text is not found.

15. split() Method

In Python, the split() method is used to divide a string into smaller parts. It returns the separated parts as a list.

var = "Guido vanRossum"
result = var.split("van")print(result)

Output:

['Guido ', 'Rossum']

Here, the string is split wherever "van" appears. The word "van" is removed from the result.

16. rsplit() Method

In Python, the rsplit() method is used to split a string from the right side. It returns the separated parts as a list.

var = "right split"
result = var.rsplit("lit")print(result)

Output:

['right sp', '']

Here, the string is split at "lit". Since "lit" occurs at the end, the second item in the list is an empty string.

You can use maxsplit to control how many times the string is split:

var = "one-two-two"
print(var.rsplit("-", 1))

Output:

['one-two', 'two']

17. partition() Method

In Python, the partition() method divides a string into three parts using a specified separator. It returns a tuple containing:

  1. The text before the separator
  2. The separator
  3. The text after the separator
var = "Python is easy to learn"
result = var.partition("easy")print(result)

Output:

('Python is ', 'easy', ' to learn')

If the separator is not found, the method returns the original string followed by two empty strings.

18. rpartition() Method

In Python, the rpartition() method divides a string into three parts using the last occurrence of a specified separator. It returns a tuple containing the text before the separator, the separator itself, and the text after it.

var = "Python is easy and Python is powerful"
result = var.rpartition("Python")print(result)

Output:

('Python is easy and ', 'Python', ' is powerful')

Unlike partition(), rpartition() searches for the separator from the right side of the string. If the separator is not found, it returns two empty strings followed by the original string.

19. str.maketrans ( ) METHOD

str.maketrans() is a built-in Python string method. It is used to create a translation table. This table tells Python which characters should be replaced with other characters.

Python is case-sensitive. For example, "mani" and "Mani" are not the same because m and M are different characters.

We usually use str.maketrans() together with the translate() method.

name = "mani"
table = str.maketrans("mani", "Teja")new_name = name.translate(table)print(new_name)

Output:

Teja
In this example:
  • m is replaced by T
  • a is replaced by e
  • n is replaced by j
  • i is replaced by a

So, the string "mani" becomes "Teja".

maketrans() only creates the replacement table. translate() applies that table to the string.

20. str. translate( ) METHOD

str.maketrans() creates a translation table for changing one character into another character.
The translate() method uses this table to replace the characters in a string.
Both methods are helpful when you want to change multiple characters at the same time

str.maketrans() is used to create a table for replacing characters in a string.
translate() uses that table and changes the specified characters.

var = "STR method is used to replace the alphabet"
var1 = str.maketrans("STR", "str")
print(var.translate(var1))

Output:

str method is used to replace the alphabet
var = "Python is a case-sensitive language."
var1 = var.center(50)
print(var1)

21. PYTHON ENGINE STRING DATA TYPE: str.center( ) METHOD

The Python string center() method is used to place a string in the middle of a new, longer string of a specified width. You pass in a number for the total width, and the original text will be centered within that width, padded with spaces (or a custom character) on both sides.

python

var = "python is a case sensitive language"
var1 = var.center(50)
print(var1)
            python is a case sensitive language        

22. PYTHON STRING DATA TYPE: is.upper( ) METHOD

Python is a case-sensitive language. The isupper() method checks whether all the alphabetic characters in a string are uppercase. It returns True if every letter is uppercase (numbers and symbols are ignored — they don't count against it), and False if any letter is lowercase. If there are no alphabetic characters at all, it returns False.

python

print("PYTHON ENGINE".isupper())

Output: True — correct, all letters are uppercase (space is ignored).

python

print("sfjDAF32".islower())

Let’s check: s, f, j are lowercase, but D, A, F are uppercase. Since not all letters are lowercase:

Output: False — correct, but let's verify why: islower() requires all cased characters to be lowercase. Since D, A, F are uppercase, it fails, hence False.

23. ISLOWER ( ) METHOD PYHTON STRING

islower() does not convert a string to lowercase. It checks whether all alphabetic characters in the string are lowercase.

Syntax:

string.islower()

Example 1:

var = "python engine"
print(var.islower())

OUTPUT

True

24. istitle( ) Python String Method

The Python string method istitle() does not convert a string into title case. It checks whether the string is already in title case and returns True or False.

If you want to convert a string into title case, use title().

Correct code

var = "python engine strings are 33 type"
print(var.title())

Output:

Python Engine Strings Are 33 Type

Checking with istitle()

var = "Python Engine Strings Are 33 Type"
print(var.istitle())
The Python string method istitle() does not convert a string into title case. It checks whether the string is already in title case and returns True or False.

If you want to convert a string into title case, use title().

Correct code
var = "python engine strings are 33 type"

print(var.title())

Output:

Python Engine Strings Are 33 Type
Checking with istitle()
var = "Python Engine Strings Are 33 Type"

print(var.istitle())

Output:

Truethe

25. isalpha( ) Method in Python String Data Type

isalpha() method:
The Python String data type is used to check whether every character in the string is an alphabetic character or not. When every character in the string is an alphabetic character, it will return True. If the string contains spaces, numbers, or special characters, it will return False.

var = "Python"
print(var.isalpha())

Note: isalpha() is a checking method. It does not convert the string.

26. isdigit() Method — Python String

The Python String method isdigit() is used to check whether the string contains only digits (numbers). If all the characters in the string are digits, it will return True. If the string contains letters, spaces, or special characters, it will return False. So, we use the isdigit() method to check whether a string contains only numbers.

var = "2384837"
print(var.isdigit())

Output:

True

Important: You need to write isdigit() with parentheses.
✅ print(var.isdigit())

27. isalnum() Method — Python String

The Python String method isalnum() is used to check whether the string contains only alphabetic characters or numbers. If the string contains only alphabets and numbers, the method will return True. If it contains spaces or special characters, it will return False.

var = "fdadk234534"
print(var.isalnum())

Output:

True

Your structure in simple theory

isalnum() method:
The Python String method is used to check whether the characters in the string are alphabetic characters or numbers. When the string contains only alphabetic characters and numbers, it returns True. If it contains spaces or special characters, it returns False.

Note: isalnum() means alphabetic + numeric.

28. isidentifier() Method — Python String Data Type

The Python String method isidentifier() is used to check whether a string is a valid identifier in Python or not. If the string follows the rules for a Python identifier, the method returns True. If it does not follow the identifier rules, it returns False.

var = "python_engine"
print(var.isidentifier())

Output:

True

Another example:

var = "123python"
pr
int(var.isidentifier())i

Output:

False

In your structure:
Python can easily identify whether a given string is a valid identifier or not. If it is a valid identifier, it returns True; otherwise, it returns False.

29. isascii() Method — Python String Data Type

The Python String method isascii() is used to check whether all characters in a string are ASCII characters or not. When all the characters belong to the ASCII character set, it will return True. If the string contains any non-ASCII character, it will return False.

var = "Python123"
print(var.isascii())

True

Another example:

var = "Python ₹"

Output:

False

In your structure:
The Python will check whether the given string contains a sequence of ASCII characters or not. When all characters are ASCII characters, the method returns True. If any character is not an ASCII character, it returns False.

30. startswith() Method — Python String Data Type

The Python String method startswith() is used to check whether a string starts with a specified character, word, or sequence of characters. If the string starts with the given value, the method returns True. If it does not start with the given value, it returns False.

var = "Python Engine"
print(var.startswith("Python"))

Output:

True

31. endswith() String Method in Python

The endswith() method is used to check whether a string ends with a specified character or sequence of characters.

It returns:

  • True → if the string ends with the specified value.
  • False → if the string does not end with the specified value.

Syntax

string.endswith(value)

Example 1: Checking the last character

name = "Python"
print(name.endswith("n"))

Output:

True

Because "Python" ends with the character "n".

Example 2: Checking the last few characters

text = "Welcome to Python"
print(text.endswith("Python")

Output:

True

Example 3: False condition

name = "Python"
print(name.endswith("P"))

Simple definition:
endswith() is a Python string method used to check whether a string ends with a specified character or substring.

32. format( ) Python Engine Data Type

var = “Enter the age {}”
print(var.format(20))

Enter the age 20

Here, "Enter the age {}" contains an empty {} placeholder. When .format(20) is applied, Python places 20 into that placeholder, and print() displays the completed string.

You can describe it in theory as follows:

Python provides the format() method to insert values into strings. Curly braces {} are used as placeholders, and the values supplied to format() are placed into those positions.

One important point is that {} is not a data type. It is a placeholder used for string formatting with the format() method.

--

--