Author name: Vikram Chiluka

Program for Python String isdigit() Method

In the previous article, we have discussed Python Program for isdecimal() Function
isdigit() Function in Python:

If all of the characters are digits, the isdigit() method returns true; otherwise, it returns False.

Exponents, such as ², are also considered digits.

Syntax:

string.isdigit()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "\u0039"
Given second string = "\u00B2"

Output:

The above given first string is : 9
The given first string after applying isdigit() function: True
The above given second string is : ²
The given second string after applying isdigit() function: True

Example2:

Input:

Given first string = "345.67"
Given second string = "python_12345"

Output:

The above given first string is : 345.67
The given first string after applying isdigit() function: False
The above given second string is : python_12345
The given second string after applying isdigit() function: False

Program for isdigit() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isdigit() function to the given first string that returns a value true if all of the characters are digits, otherwise, it returns False.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given string after applying isdigit() function.
  • Similarly, do the same for the other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "\u0039"
# Apply isdigit() function to the given first string that returns a value
# true if all of the characters are digits, otherwise, it returns False.
# Store it in another variable.
rslt_str1 = gvn_fststr.isdigit()
# Print the given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isdigit() function.
print("The given first string after applying isdigit() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "\u00B2"
rslt_str2 = gvn_scndstr.isdigit()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isdigit() function:", rslt_str2)

Output:

The above given first string is : 9
The given first string after applying isdigit() function: True
The above given second string is : ²
The given second string after applying isdigit() function: True

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isdigit() function to the given first string that returns a value true if all of the characters are digits, otherwise, it returns False.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given string after applying isdigit() function.
  • Similarly, do the same for the other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isdigit() function to the given first string that returns a value
# true if all of the characters are digits, otherwise, it returns False.
# Store it in another variable.
rslt_str1 = gvn_fststr.isdigit()
# Print the given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isdigit() function.
print("The given first string after applying isdigit() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isdigit()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isdigit() function:", rslt_str2)

Output:

Enter some Random String = 345.67
The above given first string is : 345.67
The given first string after applying isdigit() function: False
Enter some Random String = python_12345
The above given second string is : python_12345
The given second string after applying isdigit() function: False

Are you facing difficulties in finding all the methods that a string object can call in python? Have a glance at this Python String Method Examples Tutorial & meet such challenges with ease.

Program for Python String isdigit() Method Read More »

Program for Python String isdecimal() Method

In the previous article, we have discussed Python Program for gamma() Function
isdecimal() Function in Python:

If all of the characters are decimals(0-9), the isdecimal() method returns True.

On unicode objects, this method is used.

Syntax:

string.isdecimal()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "123456789_python"
Given second string = "92567"

Output:

The above given first string is : 123456789_python
The given first string after applying isdecimal() function: False
The above given second string is : 92567
The given second string after applying isdecimal() function: True

Example2:

Input:

Given first string = "\u0039"  (#unicode for 9)
Given second string = "92567"

Output:

The above given first string is : 9
The given first string after applying isdecimal() function: True
The above given second string is : 92567
The given second string after applying isdecimal() function: True

Program for isdecimal() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isdecimal() function to the given first string that returns a value true if all of the characters are decimals(0-9).
  • Store it in another variable.
  • Print the given String.
  • Print the above-given String after applying isdecimal() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "123456789_python"
# Apply isdecimal() function to the given first string that returns a value
# true if all of the characters are decimals(0-9).
# Store it in another variable.
rslt_str1 = gvn_fststr.isdecimal()
# Print the given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isdecimal() function.
print("The given first string after applying isdecimal() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "92567"
rslt_str2 = gvn_scndstr.isdecimal()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isdecimal() function:", rslt_str2)

Output:

The above given first string is : 123456789_python
The given first string after applying isdecimal() function: False
The above given second string is : 92567
The given second string after applying isdecimal() function: True

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isdecimal() function to the given first string that returns a value true if all of the characters are decimals(0-9).
  • Store it in another variable.
  • Print the given String.
  • Print the above-given String after applying isdecimal() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isdecimal() function to the given first string that returns a value
# true if all of the characters are decimals(0-9).
# Store it in another variable.
rslt_str1 = gvn_fststr.isdecimal()
# Print the given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isdecimal() function.
print("The given first string after applying isdecimal() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isdecimal()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isdecimal() function:", rslt_str2)

Output:

Enter some Random String = goodmorning456288729
The above given first string is : goodmorning456288729
The given first string after applying isdecimal() function: False
Enter some Random String = 90876123
The above given second string is : 90876123
The given second string after applying isdecimal() function: True

Are you facing difficulties in finding all the methods that a string object can call in python? Have a glance at this Python String Method Examples Tutorial & meet such challenges with ease.

Program for Python String isdecimal() Method Read More »

Program for Python String isalpha() Method

In the previous article, we have discussed Python Program for isalnum() Function
isalpha() Function in Python:

If all of the characters are alphabet letters, the isalpha() method returns True (a-z).

(space)!#%&? etc are examples of characters that are not alphabets.

Syntax:

string.isalpha()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "pythonprograms"
Given second string = "123456good morning"

Output:

The above given first string is : pythonprograms
The given first string after applying isalpha() function: True
The above given second string is : 123456good morning
The given second string after applying isalpha() function: False

Example2:

Input:

Given first string = "hello123this is python programming platform"
Given second string = "hellogoodmorning"

Output:

The above given first string is : hello123this is python programming platform
The given first string after applying isalpha() function: False
The above given second string is : hellogoodmorning
The given second string after applying isalpha() function: True

Program for isalpha() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isalpha() function to the given first string that returns true if all of the characters are alphabet letters.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello123this is python programming platform"
# Apply isalpha() function to the given first string that returns true if
# all of the characters are alphabet letters.
# Store it in another variable.
rslt_str1 = gvn_fststr.isalpha()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalpha() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "hellogoodmorning"
rslt_str2 = gvn_scndstr.isalpha()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalpha() function:", rslt_str2)

Output:

The above given first string is : hello123this is python programming platform
The given first string after applying isalpha() function: False
The above given second string is : hellogoodmorning
The given second string after applying isalpha() function: True

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isalpha() function to the given first string that returns true if all of the characters are alphabet letters.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isalpha() function to the given first string that returns true if
# all of the characters are alphabet letters.
# Store it in another variable.
rslt_str1 = gvn_fststr.isalpha()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalpha() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isalpha()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalpha() function:", rslt_str2)

Output:

Enter some Random String = pythonprograms
The above given first string is : pythonprograms
The given first string after applying isalpha() function: True
Enter some Random String = 123456good morning
The above given second string is : 123456good morning
The given second string after applying isalpha() function: False

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String isalpha() Method Read More »

Program for Python String isalnum() Method

In the previous article, we have discussed Python Program for center() Function
isalnum() Function in Python:

The isalnum() method returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).

(space)!#%&? etc are examples of characters that are not alphanumeric.

Syntax:

string.isalnum()

Parameters: This function has no parameters.

Examples:

Example1:

Input:

Given first string = "pythonprograms"
Given second string = "10345 @@@good morning"

Output:

The above given first string is : pythonprograms
The given first string after applying isalnum() function: True
The above given second string is : 10345 @@@good morning
The given second string after applying isalnum() function: False

Example2:

Input:

Given first string = "hello this is python programming platform"
Given second string = "hello123"

Output:

The above given first string is : hello this is python programming platform
The given first string after applying isalnum() function: False
The above given second string is : hello123
The given second string after applying isalnum() function: True

Program for isalnum() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply isalnum() function to the given first string that returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "pythonprograms"
# Apply isalnum() function to the given first string that returns a value
# True if all of the characters are alphanumeric, which means they are alphabet
# letters (a-z) and numbers (0-9).
# Store it in another variable.
rslt_str1 = gvn_fststr.isalnum()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalnum() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "10345 @@@good morning"
rslt_str2 = gvn_scndstr.isalnum()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalnum() function:", rslt_str2)

Output:

The above given first string is : pythonprograms
The given first string after applying isalnum() function: True
The above given second string is : 10345 @@@good morning
The given second string after applying isalnum() function: False

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply isalnum() function to the given first string that returns a value True if all of the characters are alphanumeric, which means they are alphabet letters (a-z) and numbers (0-9).
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying isalnum() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply isalnum() function to the given first string that returns a value
# True if all of the characters are alphanumeric, which means they are alphabet
# letters (a-z) and numbers (0-9).
# Store it in another variable.
rslt_str1 = gvn_fststr.isalnum()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying isalnum() function.
print("The given first string after applying isalnum() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.isalnum()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying isalnum() function:", rslt_str2)

Output:

Enter some Random String = hello this is python programming platform
The above given first string is : hello this is python programming platform
The given first string after applying isalnum() function: False
Enter some Random String = hello123
The above given second string is : hello123
The given second string after applying isalnum() function: True

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String isalnum() Method Read More »

Program for Python String center() Method

In the previous article, we have discussed Python Program for casefold() Function
center() Function in Python:

The center () method will center align the string, using a specified character as the fill character (space is the default).

Syntax:

String.center(Length, character)

Parameters:

length: This is required. It is the length of the string returned.

character: This is optional. Fills the blanks on each side with a character. The default value is ” ” (space).

Note: This parameter is optional, and if omitted, the white spaces are used as the default parameter by the centre Function. Please specify the Characters you want to use in the remaining width if you want to change the default value.

Examples:

Example1:

Input:

Given first string = "python"
Given length = 30 
Given character = '-'

Output:

The above given first string is : python
The given first string after applying center() function: ------------python------------

Example2:

Input:

Given second string = "GOODMORNING"
Given length = 17
Given character = '#'

Output:

The above given second string is : GOODMORNING
The given second string after applying center() function: ###GOODMORNING###

Program for center() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Give the length as static input and store it in another variable.
  • Give the character as static input and store it in another variable.
  • Apply center () method to the given string for the given length and character which will center align the string.
  • Store it in another variable.
  • Print the above-given string.
  • Print the above-given string after applying the center() function.
  • Similarly, do the same for the other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "python"
# Give the length as static input and store it in another variable.
gvn_lengt = 30
# Give the character as static input and store it in another variable.
gvn_chactr = '-'
# Apply center () method to the given string for the given length and character
# which will center align the string.
# Store it in another variable.
rslt_str1 = gvn_fststr.center(gvn_lengt, gvn_chactr)
# Print the above given string
print("The above given first string is :", gvn_fststr)
# Print the above given string after applying center() function.
print("The given first string after applying center() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "GOODMORNING"
gvn_lengt2 = 17
gvn_chactr2 = '#'
rslt_str2 = gvn_scndstr.center(gvn_lengt2, gvn_chactr2)
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying center() function:", rslt_str2)

Output:

The above given first string is : python
The given first string after applying center() function: ------------python------------
The above given second string is : GOODMORNING
The given second string after applying center() function: ###GOODMORNING###

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Give the length as user input using the int(input()) function and store it in another variable.
  • Give the character as user input using the input() function and store it in another variable.
  • Apply center () method to the given string for the given length and character which will center align the string.
  • Store it in another variable.
  • Print the above-given string.
  • Print the above-given string after applying the center() function.
  • Similarly, do the same for the other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr =  input("Enter some random string = ")
# Give the length as user input using the int(input()) function and store it in another variable.
gvn_lengt = int(input("Enter some random number = "))
# Give the character as user input using the input() function and store it in another variable.
gvn_chactr = input("Enter some random charcter = ")
# Apply center () method to the given string for the given length and character
# which will center align the string.
# Store it in another variable.
rslt_str1 = gvn_fststr.center(gvn_lengt, gvn_chactr)
# Print the above given string
print("The above given first string is :", gvn_fststr)
# Print the above given string after applying center() function.
print("The given first string after applying center() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some random string = ")
gvn_lengt2 =  int(input("Enter some random number = "))
gvn_chactr2 = input("Enter some random charcter = ")
rslt_str2 = gvn_scndstr.center(gvn_lengt2, gvn_chactr2)
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying center() function:", rslt_str2)

Output:

Enter some random string = welcome
Enter some random number = 16
Enter some random charcter = !
The above given first string is : welcome
The given first string after applying center() function: !!!!welcome!!!!!
Enter some random string = PYTHONPLATFORM
Enter some random number = 8
Enter some random charcter = *
The above given second string is : PYTHONPLATFORM
The given second string after applying center() function: PYTHONPLATFORM

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

 

Program for Python String center() Method Read More »

Program for Python String casefold() Method

In the previous article, we have discussed Python Program for capitalize() Function
casefold() Function in Python:

The casefold() method produces a string in which all of the characters are lower case.

This method is similar to lower(), but the casefold() method is stronger and more aggressive, which means it will convert more characters into lower case and find more matches when comparing two strings that have both been converted using the casefold() method.

Syntax:

string.casefold()

Parameters: This function doesn’t have any parameters.

Examples:

Example1:

Input:

Given first string = "hello this is BTECHGEEKS"
Given second string = "10345 GOOD MORNING btechgeeks"

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying casefold() function: hello this is btechgeeks
The above given second string is : 10345 GOOD MORNING btechgeeks
The given second string after applying casefold() function: 10345 good morning btechgeeks

Example2:

Input:

Given first string = "HeLLO ThiS is BTECHgeeks 12345"
Given second string = "GOOD MORNING THIS IS BTECHGEEKS"

Output:

The above given first string is : HeLLO ThiS is BTECHgeeks 12345
The given first string after applying casefold() function: hello this is btechgeeks 12345
The above given second string is : GOOD MORNING THIS IS BTECHGEEKS
The given second string after applying casefold() function: good morning this is btechgeeks

Program for casefold() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply casefold() function to the given first string to get the string in which all of the characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying casefold() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello this is BTECHGEEKS"
# Apply casefold() function to the given first string to get the string
# in which all of the characters are lower case.
# Store it in another variable.
rslt_str1 = gvn_fststr.casefold()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying casefold() function.
print("The given first string after applying casefold() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "10345 GOOD MORNING btechgeeks"
rslt_str2 = gvn_scndstr.casefold()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying casefold() function:", rslt_str2)

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying casefold() function: hello this is btechgeeks
The above given second string is : 10345 GOOD MORNING btechgeeks
The given second string after applying casefold() function: 10345 good morning btechgeeks

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply casefold() function to the given first string to get the string in which all of the characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying casefold() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply casefold() function to the given first string to get the string
# in which all of the characters are lower case.
# Store it in another variable.
rslt_str1 = gvn_fststr.casefold()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying casefold() function.
print("The given first string after applying casefold() function:", rslt_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
rslt_str2 = gvn_scndstr.casefold()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying casefold() function:", rslt_str2)

Output:

Enter some Random String = hello all this IS BTECHGEEKS
The above given first string is : hello all this IS BTECHGEEKS
The given first string after applying casefold() function: hello all this is btechgeeks
Enter some Random String = GOOD MORNING THIS IS BTECHGEEKS
The above given second string is : GOOD MORNING THIS IS BTECHGEEKS
The given second string after applying casefold() function: good morning this is btechgeeks

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String casefold() Method Read More »

Program for Python String capitalize() Function

In the previous article, we have discussed Python Program for hypot() Function
capitalize() Function in Python:

The capitalize() method returns a string in which the first character is upper case and the remaining characters are lower case.

Non-letters are not capitalized by the string capitalize function.

Syntax:

string.capitalize()

Parameters: This function doesn’t have any parameters.

Examples:

Example1:

Input:

Given first string = "hello this is BTECHGEEKS"
Given second string = "10345 good morning btechgeeks"

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying capitalize() function: Hello this is btechgeeks
The above given second string is : 10345 good morning btechgeeks
The given second string after applying capitalize() function: 10345 good morning btechgeeks

Example2:

Input:

Given first string = "heLLO 1256 GOOd MOrning"
Given second string = "Hello btech137GEEKS"

Output:

The above given first string is : heLLO 1256 GOOd MOrning
The given first string after applying capitalize() function: Hello 1256 good morning
The above given second string is : Hello btech137GEEKS
The given second string after applying capitalize() function: Hello btech137geeks

Program for capitalize() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Give the first string as static input and store it in a variable.
  • Apply capitalize() function to the given first string to get the string in which the first character is upper case and the remaining characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying capitalize() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as static input and store it in a variable.
gvn_fststr = "hello this is BTECHGEEKS"
# Apply capitalize() function to the given first string to get the string in which
# the first character is upper case and the remaining characters are lower case.
# Store it in another variable.
capitize_str1 = gvn_fststr.capitalize()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying capitalize() function.
print("The given first string after applying capitalize() function:", capitize_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = "10345 good morning btechgeeks"
capitize_str2 = gvn_scndstr.capitalize()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying capitalize() function:", capitize_str2)

Output:

The above given first string is : hello this is BTECHGEEKS
The given first string after applying capitalize() function: Hello this is btechgeeks
The above given second string is : 10345 good morning btechgeeks
The given second string after applying capitalize() function: 10345 good morning btechgeeks

Method #2: Using Built-in Functions (User Input)

Approach:

  • Give the first string as user input using the input() function and store it in a variable.
  • Apply capitalize() function to the given first string to get the string in which the first character is upper case and the remaining characters are lower case.
  • Store it in another variable.
  • Print the above-given String.
  • Print the above-given String after applying capitalize() function.
  • Similarly, do the same for other string and print the result string.
  • The Exit of Program.

Below is the implementation:

# Give the first string as user input using the input() function and store it in a variable.
gvn_fststr = input("Enter some Random String = ")
# Apply capitalize() function to the given first string to get the string in which
# the first character is upper case and the remaining characters are lower case.
# Store it in another variable.
capitize_str1 = gvn_fststr.capitalize()
# Print the above given String
print("The above given first string is :", gvn_fststr)
# Print the above given String after applying capitalize() function.
print("The given first string after applying capitalize() function:", capitize_str1)
# Similarly do the same for other string and print the result string.
gvn_scndstr = input("Enter some Random String = ")
capitize_str2 = gvn_scndstr.capitalize()
print("The above given second string is :", gvn_scndstr)
print("The given second string after applying capitalize() function:", capitize_str2)

Output:

Enter some Random String = heLLO 1256 GOOd MOrning
The above given first string is : heLLO 1256 GOOd MOrning
The given first string after applying capitalize() function: Hello 1256 good morning
Enter some Random String = Hello btech137GEEKS
The above given second string is : Hello btech137GEEKS
The given second string after applying capitalize() function: Hello btech137geeks

Go through our tutorial and learn about various Python String Method Examples and learn how to apply the knowledge while dealing with strings.

Program for Python String capitalize() Function Read More »

Python Program for asinh() Function

In the previous article, we have discussed Python Program for acosh() Function
asinh() Function in Python:

The inverse hyperbolic sine of a number is returned by the math.asinh() method.

Syntax:

math.asinh(x)

Parameter:

x: This is required. It is a positive or a negative number. If x is not a number, a TypeError is returned.

Return Value:

Returns a float value representing a number’s inverse hyperbolic sine.

  • The asinh function returns the hyperbolic Arc Sine value if the number argument is positive or negative.
  • The asinh functions return TypeError if it is not a number.

Examples:

Example1:

Input:

Given first number = 9
Given second number = 45

Output:

The result after applying asinh() function on above given first number 9  =  2.8934439858858716
The result after applying asinh() function on above given second number 45  =  4.49993310426429

Example2:

Input:

Given first number = 30
Given second number = 60

Output:

The result after applying asinh() function on above given first number 30  =  4.09462222433053
The result after applying asinh() function on above given second number 60  =  4.78756117999381

Program for asinh() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as static input and store it in a variable.
  • Give the first number as static input and store it in another variable.
  • Apply math.asinh() function to the given first number to get the inverse hyperbolic sine of a given number
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.asinh() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as static input and store it in a variable.
gvn_lst = [1, 4, 6, 3]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 9
# Apply math.asinh() function to the given first number to get the inverse
# hyperbolic sine of a given number
# Store it in another variable.
fnl_rslt = math.asinh(gvn_numb1)
# Print the above result.
print("The result after applying asinh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 45
print("The result after applying asinh() function on above given second number",
      gvn_numb2, " = ", math.asinh(gvn_numb2))
# Apply math.asinh() function to the given list element and print it.
print(
    "The result after applying asinh() function on given list element gvnlst[1] = ", math.asinh(gvn_lst[1]))

Output:

The result after applying asinh() function on above given first number 9  =  2.8934439858858716
The result after applying asinh() function on above given second number 45  =  4.49993310426429
The result after applying asinh() function on given list element gvnlst[1] =  2.0947125472611012

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the first number as user input using the float(input()) function and store it in a variable.
  • Apply math.asinh() function to the given first number to get the inverse hyperbolic sine of a given number
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.asinh() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_lst = list(map(float, input(
    'Enter some random List Elements separated by spaces = ').split()))
# Give the first number as user input using the float(input()) function
# and store it in a variable.
gvn_numb1 = float(input("Enter some random number = "))
# Apply math.asinh() function to the given first number to get the inverse
# hyperbolic sine of a given number
# Store it in another variable.
fnl_rslt = math.asinh(gvn_numb1)
# Print the above result.
print("The result after applying asinh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = float(input("Enter some random number = "))
print("The result after applying asinh() function on above given second number",
      gvn_numb2, " = ", math.asinh(gvn_numb2))
# Apply math.asinh() function to the given list element and print it.
print(
    "The result after applying asinh() function on given list element gvnlst[2] = ", math.asinh(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 15 25 35 45
Enter some random number = 30
The result after applying asinh() function on above given first number 30.0 = 4.09462222433053
Enter some random number = 60
The result after applying asinh() function on above given second number 60.0 = 4.78756117999381
The result after applying asinh() function on given list element gvnlst[2] = 4.248699261236361

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for asinh() Function Read More »

Python Program for atanh() Function

In the previous article, we have discussed Python Program for asinh() Function
atanh() Function in Python:

The inverse hyperbolic tangent of a number is returned by the math.atanh() method.

Note: It should be noted that the parameter passed in math.atanh() must be between -0.99 and 0.99.

Syntax:

math.atanh(x)

Parameters:

x: This is required. It is a number between -0.99 and 0.99 that is positive or negative. If x is not a number, a TypeError is returned.

Return Value:

Returns a float value representing a number’s inverse hyperbolic tangent.

  • The atanh function returns the Hyperbolic Arc Tangent value if the number argument is both positive and negative.
  • The atanh function returns ValueError if it is not between -1 (exclude) and 1 (exclude).
  • If it is not a number, the atanh function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 0.6
Given second number = -0.8

Output:

The result after applying atanh() function on above given first number 0.6  =  0.6931471805599453
The result after applying atanh() function on above given second number -0.8  =  -1.0986122886681098

Example2:

Input:

Given first number = 0.54
Given second number = -0.9

Output:

The result after applying atanh() function on above given first number 0.54  =  0.6041556029622671
The result after applying atanh() function on above given second number -0.9  =  -1.4722194895832204

Program for acosh() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as static input and store it in a variable.
  • Give the first number as static input and store it in another variable.
  • Apply math.atanh() function to the given first number to get the inverse hyperbolic tangent of a given number
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.atanh() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as static input and store it in a variable.
gvn_lst = [0.25, 0.35, 1, 4]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 0.6
# Apply math.atanh() function to the given first number to get the inverse
# hyperbolic tangent of a given number
# Store it in another variable.
fnl_rslt = math.atanh(gvn_numb1)
# Print the above result.
print("The result after applying atanh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = -0.8
print("The result after applying atanh() function on above given second number",
      gvn_numb2, " = ", math.atanh(gvn_numb2))
# Apply math.atanh() function to the given list element and print it.
print(
    "The result after applying atanh() function on given list element gvnlst[1] = ", math.atanh(gvn_lst[1]))

Output:

The result after applying atanh() function on above given first number 0.6  =  0.6931471805599453
The result after applying atanh() function on above given second number -0.8  =  -1.0986122886681098
The result after applying atanh() function on given list element gvnlst[1] =  0.36544375427139614

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the first number as user input using the float(input()) function and store it in a variable.
  • Apply math.atanh() function to the given first number to get the inverse hyperbolic tangent of a given number
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.atanh() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_lst = list(map(float, input(
    'Enter some random List Elements separated by spaces = ').split()))
# Give the first number as user input using the float(input()) function
# and store it in a variable.
gvn_numb1 = float(input("Enter some random number = "))
# Apply math.atanh() function to the given first number to get the inverse
# hyperbolic tangent of a given number
# Store it in another variable.
fnl_rslt = math.atanh(gvn_numb1)
# Print the above result.
print("The result after applying atanh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = float(input("Enter some random number = "))
print("The result after applying atanh() function on above given second number",
      gvn_numb2, " = ", math.atanh(gvn_numb2))
# Apply math.atanh() function to the given list element and print it.
print(
    "The result after applying atanh() function on given list element gvnlst[2] = ", math.atanh(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 0.1 0.2 -0.3 4.4
Enter some random number = 0.54
The result after applying atanh() function on above given first number 0.54 = 0.6041556029622671
Enter some random number = -0.9
The result after applying atanh() function on above given second number -0.9 = -1.4722194895832204
The result after applying atanh() function on given list element gvnlst[2] = -0.30951960420311175

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for atanh() Function Read More »

Python Program for acosh() Function

In the previous article, we have discussed Python Program for tan() Function
acosh() Function in Python:

The inverse hyperbolic cosine of a number is returned by the math.acosh() method.

It should be noted that the parameter passed to acosh() must be greater than or equal to 1.

Syntax:

math.acosh(x)

Parameter:

x: This is required. A positive number greater than or equal to one. If x is not a number, a TypeError is returned.

Return Value:

The inverse hyperbolic cosine of x is represented as a float in the return value.

  • The acosh function returns the hyperbolic Arc Cosine value if the number argument is positive.
  • If the value is negative, the acosh function returns ValueError.
  • If it’s not a number, the acosh function throws a TypeError.

Examples:

Example1:

Input:

Given first number = 8
Given second number = 36

Output:

The result after applying acosh() function on above given first number 8  =  2.7686593833135738
The result after applying acosh() function on above given second number 36  =  4.276473161941219

Example2:

Input:

Given first number = 14.5
Given second number = 25

Output:

The result after applying acosh() function on above given first number 14.5  =  3.366104642925109
The result after applying acosh() function on above given second number 25  =  3.9116227652145885

Program for acosh() Function in Python

Method #1: Using Built-in Functions (Static Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as static input and store it in a variable.
  • Give the first number as static input and store it in another variable.
  • Apply math.acosh() function to the given first number to get inverse hyperbolic cosine of a given number
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.acosh() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as static input and store it in a variable.
gvn_lst = [1, 5, 6, 3]
# Give the first number as static input and store it in another variable.
gvn_numb1 = 8
# Apply math.acosh() function to the given first number to get inverse
# hyperbolic cosine of a given number
# Store it in another variable.
fnl_rslt = math.acosh(gvn_numb1)
print("The result after applying acosh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = 36
print("The result after applying acosh() function on above given second number",
      gvn_numb2, " = ", math.acosh(gvn_numb2))
# Apply math.acosh() function to the given list element and print it.
print(
    "The result after applying acosh() function on given list element gvnlst[1] = ", math.acosh(gvn_lst[1]))

Output:

The result after applying acosh() function on above given first number 8  =  2.7686593833135738
The result after applying acosh() function on above given second number 36  =  4.276473161941219
The result after applying acosh() function on given list element gvnlst[1] =  2.2924316695611777

Method #2: Using Built-in Functions (User Input)

Approach:

  • Import math module using the import keyword.
  • Give the list as user input using list(),map(),input(),and split() functions.
  • Store it in a variable.
  • Give the first number as user input using the float(input()) function and store it in a variable.
  • Apply math.acosh() function to the given first number to get inverse hyperbolic cosine of a given number
  • Store it in another variable.
  • Print the above result.
  • Similarly, do the same for the other number.
  • Apply math.acosh() function to the given list element and print it.
  • The Exit of Program.

Below is the implementation:

# Import math module using the import keyword.
import math
# Give the list as user input using list(),map(),input(),and split() functions.
# Store it in a variable.
gvn_lst = list(map(float, input(
    'Enter some random List Elements separated by spaces = ').split()))
# Give the first number as user input using the float(input()) function
# and store it in a variable.
gvn_numb1 = float(input("Enter some random number = "))
# Apply math.acosh() function to the given first number to get inverse
# hyperbolic cosine of a given number
# Store it in another variable.
fnl_rslt = math.acosh(gvn_numb1)
print("The result after applying acosh() function on above given first number",
      gvn_numb1, " = ", fnl_rslt)
# similarly do the same for the other number.
gvn_numb2 = float(input("Enter some random number = "))
print("The result after applying acosh() function on above given second number",
      gvn_numb2, " = ", math.acosh(gvn_numb2))
# Apply math.acosh() function to the given list element and print it.
print(
    "The result after applying acosh() function on given list element gvnlst[2] = ", math.acosh(gvn_lst[2]))

Output:

Enter some random List Elements separated by spaces = 10 20 30 50 
Enter some random number = 14.5
The result after applying acosh() function on above given first number 14.5 = 3.366104642925109
Enter some random number = 25
The result after applying acosh() function on above given second number 25.0 = 3.9116227652145885
The result after applying acosh() function on given list element gvnlst[2] = 4.0940666686320855

Know all about Mathematical Functions in Python by going through our Python Mathematical Methods Examples well explained step by step.

Python Program for acosh() Function Read More »