STRINGS
Strings in Programming Languages
A string is a sequence of characters, often used to represent text in programming. Strings
are fundamental data types in most programming languages and are typically enclosed in
quotation marks (" " or ' ').
Strings in Python
In Python, a string is a sequence of characters enclosed in quotes (single, double, or triple).
Strings are immutable, meaning they cannot be changed after creation.
Creating Strings
1.Single Quotes
single_quoted_string = 'Hello, World!'
2.Double Quotes
double_quoted_string = "Hello, World!"
3.Triple Quotes
triple_quoted_string = """Hello,
World!"""
String Operation
1.Concatenation
greeting = "Hello, "
name = "John"
full_greeting = greeting + name
print(full_greeting) # Output: Hello, John
2.Repetition
repeated_string = "Hello" * 3
print(repeated_string) # Output: HelloHelloHello
3.Indexing
string = "Hello"
print(string[0]) # Output: H
print(string[-1]) # Output: o
4.Slicing
string = "Hello"
print(string[1:3]) # Output: el
Strings in Programming Languages
A string is a sequence of characters, often used to represent text in programming. Strings
are fundamental data types in most programming languages and are typically enclosed in
quotation marks (" " or ' ').
Strings in Python
In Python, a string is a sequence of characters enclosed in quotes (single, double, or triple).
Strings are immutable, meaning they cannot be changed after creation.
Creating Strings
1.Single Quotes
single_quoted_string = 'Hello, World!'
2.Double Quotes
double_quoted_string = "Hello, World!"
3.Triple Quotes
triple_quoted_string = """Hello,
World!"""
String Operation
1.Concatenation
greeting = "Hello, "
name = "John"
full_greeting = greeting + name
print(full_greeting) # Output: Hello, John
2.Repetition
repeated_string = "Hello" * 3
print(repeated_string) # Output: HelloHelloHello
3.Indexing
string = "Hello"
print(string[0]) # Output: H
print(string[-1]) # Output: o
4.Slicing
string = "Hello"
print(string[1:3]) # Output: el