Built-in String Functions

Overview

Python provides several built-in functions to work with strings. These methods make it easier to manipulate and analyze text data.

Examples

# Example 1: len() - Get the length of the string
text = "Hello, World!"
print(len(text))           # 13
# Example 2: str() - Convert another data type to a string
number = 123
converted = str(number)
print(converted)           # "123"
print(type(converted))     # <class 'str'>
# Example 3: type() - Check the type of the object
word = "Python"
print(type(word))          # <class 'str'>
# Example 4: print() - Display output to the console
name = "John"
print("Hello", name)       # Hello John
# Example 5: input() - Get input from the user
# Uncomment to test interactively
# user_input = input("Enter your name: ")
# print("Hi", user_input)