String In Python

                                  String In Python


String is a sequence of characters. String is one of the most common used type in python. We can create a string simply by enclosing a set of characters inside a pair of single quote(' ') or inside a pair of double quote(" ") . Creating strings is as simple as assigning a value to a variable.
Example -->
name = 'Python'
typ = "programming language" 
print(name)
print(typ)

Output-->
Python
programming language


Python provides various inbuilt string manipulation functions , which are really helpful for implementing various tasks . We will discuss about it in later. Some of the commonly used string manipulation functions are listed below:
  • len()
  • capitalize()
  • upper()
  • lower()
  • swapcase()
  • lstrip()
  • rstrip()
  • strip()
  • isalnum()
  • isalpha()
  • isdigit()
  • Concatenate
  • Append


1. len()
We can determine the number of characters in a string using len() . In len() the blank space counts as a separate character.


2capitalize()
Capitalizes first letter of string.,


3. upper()
Converts lowercase letters in string to uppercase.


4. lower()
Converts all uppercase letters in string to lowercase.


5. swapcase()
Inverts case for all letters in string.


6. lstrip()
Removes all leading whitespace in string.


7. rstrip()
Removes all trailing whitespace of string.


8. strip()
Performs both lstrip() and rstrip() on string.


9. isalnum()
Returns true if string has at least 1 character and all characters are alphanumeric and false otherwise.


10. isalpha()
Returns true if string has at least 1 character and all characters are alphabetic and false otherwise.


11. isdigit()
Returns true if string contains only digits and false otherwise.


12. Concatenate
This term means to join strings together. The process is known as concatenating strings and it is done using the plus (+) operator. Note that you must be explicit about where you want blank spaces to occur by placing them between single quotation marks also.


13. Append()
Used to attach another string in end of a string.


Comments