concat python

 concatenation:

  • In python, concatenation is defined as "the process of combining or joining or merging one string with the other string".
  •  It uses the plus operator for combining the strings.
  • The string must be enclosed with single quotations or double.
  • Type conversion is needed.
  • We can combine an integer value with a string by using the str(int) function.
  • The plus(+) operator is used to combine the string at the end of the string.
  • The % string format operator is used to combine the string anywhere we want.
Syntax: str1+str2

#write a python program to demonstrate concatenation function.

  1. a="python"
  2. b="programming"
  3. x=a+b
  4. print(x)
  5. str1="python"
  6. str2=str(3.0)
  7. str=str1+str2
  8. print(str)
Output: pythonprogramming
              python3.0



startswith python

  •  In python, we have another built-in method called startswith.
  • startswith is used to check whether the string startswith this specified string.
  • It returns the boolean type.
  • If the string startswith gave specified string then it returns true else false.
Syntax: str.startswith(value,start,end)

  • It consists of the 3 parameters.
  1. value:  The value that the string starts with.
  2. start:    The position to start the search of string.
  3. end:  The position to end the search.

#write a python program to demonstrate the startswith method.

  1. str="welcome to python"
  2. str=str.startswith("w",0,14)
  3. print(str)
Output:true

strftime python

 strftime :

  •  The method represents the string consists of data and time with objects as time and date or date time.
  • The datetime class is imported from the date time module.
  • It takes one or more input format codes and returns string representation.
Syntax: strftime(format)

  • The list of format codes are:
  1. %a:  It is used for weekdays representation in short forms as wed, thr, etc...
  2. %A: It is used for weekdays representation in the full name as of Sunday, Monday.
  3. %b: It is used for month name representation in short form as of Jan, Feb, etc
  4. %B: It is used for month name representation in the full name as of April, May, etc.
  5. %d: It is used as a representation of the day of the month as zero added.
  6.  %-d: day of the month as a decimal number.
  7. %m: Month as zero added decimal number. 
  8. %-m: Month as a decimal number.
  9. %H:  hours as zero added decimal number.
  10. %-H: hours as a decimal number.
  11. %M: minutes as zero added decimal number.
  12. %-M: minutes as a decimal number.
  13. %S: seconds as a zero added decimal number
  14. %-S: seconds as a decimal number.
  15. %J: day of the year as zero added decimal number.
  16. %-J: day of the year as a decimal number.

#write a python program to demonstrate strftime function.

  1. from datetime import datetime
  2. now=datetime.now()
  3. year=now.strftime("%Y")
  4. print("year:",year)
  5. month=now.strftime("%m")
  6. print("month:",month)
  7. day=now.strftime("%d")
  8. print("day:",day)
  9. time=now.strftime("%H:%M:%S")
  10. print("time:",time)
  11. date_time=now.strftime("%m%d%Y, %H%M%S")
  12. print("date and time:",date_time)
output:
year:2021
month:07
day:05
time:10:50:36
date and time:07052021,105036



is numeric python

is numeric:

  •  Is numeric is the built-in method that is used to check whether the string contains numbers or not.
  • It returns the true when the string contains numbers, if the string does not contain numbers then it returns false.
  • It is applicable for integers, Unicode values. and takes the exponents like 1/2.
  • It is not applicable for float and negative values.
  •  isnumeric does not have any parameters.
  • For negative values to check whether they are numeric or not we have to remove the negative sign.
syntax:  str.isnumeric()

Example: a="12345"

                 a=str.isnumeric(a)

                 true

#write a python program to demonstrate the isnumeric function.

  1. x="34567"
  2. x=str.isnumeric(x)
  3. print(x)
  4. y="123abc"
  5. y=str.isnumeric(y)
  6. priny(y)
  7. z="asd13434656"
  8. z=str.isnumeric(z)
  9. print(z)
output: true
             false
             false




 

is alpha python

 is alpha:

  • In python "is alpha" is the method used to check the alphabets whether they are present in the given string or substring.
  • In isalpha, it must carry only alphabets.
  • It carries the result in the boolean type
  • If the string contains all alphabets then it returns true, else false.
  • The isalpha is not applicable for the alphanumeric.
  • It is the built-in function of python.
syntax: str.isalpha()

Example:  s="abcdefg"
                   str.isalpha(s)
                    true

#write a python program to demonstrate is alpha function.

  1. a="india"
  2. b="india123"
  3. a=str.isalpha(a)
  4. b=str.isalpha(b)
  5. print(a)
  6. print(b)
output: true
             false


is digit python

is digit() python:  

  • The isdigit()  in python is defined as the string that consists of only digit values. 
  • It returns the result in boolean type if the string has only digits it returns true else false.
  • It accepts the Unicode of that characters also. and also the exponents like ^2.
  • It is not applicable to whitespace, special symbols, alphabets.
Syntax: str.isdigit().

Example:  str="123456"
                 str.isdigit(str) retrns true
Beacuse "123456" is perfectly a digit.
               str=\u00B0
               str.isdigit(str)returns true
Because it takes the Unicode as digit characters.

#write a python code  to demonstrate isdigit() function.

  1. a="7656734"
  2. a=str.isdigit(a)
  3. print(a)
  4. b="2344.60 
  5. b=str.isdigit(b)
  6. print(b)
  7. x="\u00B2"
  8. x=str.isdiigt(x)
  9. print(x)
output: true
            false
            true

2

Select Menu