-
Hajipur, Bihar, 844101
Hajipur, Bihar, 844101
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms
Strings in Python are used to store text. A string is a sequence of characters enclosed in single or double quotes.
a = "Hello"
b = 'World'
print(a, b)
Use triple quotes for multiline strings.
text = """This is a
multiline string."""
print(text)
Each character in a string has an index. The first character has index 0.
a = "Python"
print(a[0]) # Output: P
print(a[1]) # Output: y
for letter in "Python":
print(letter)
Use len()
to get the number of characters in a string.
a = "Hello"
print(len(a)) # Output: 5
Use the in
keyword to check if a word or letter is in the string.
text = "Python is fun"
print("fun" in text) # Output: True
a = "Programming"
print(a[0:6]) # Output: Progra
print(a[:4]) # Output: Prog
print(a[4:]) # Output: ramming
text = " Hello World "
print(text.lower()) # hello world
print(text.upper()) # HELLO WORLD
print(text.strip()) # Hello World
print(text.replace("World", "Python")) # Hello Python
print(text.split()) # ['Hello', 'World']
a = "Hello"
b = "Python"
c = a + " " + b
print(c)
Use backslash \
to escape characters.
print("He said \"Hello\"")
Practice string slicing, concatenation, indexing, and built-in methods.
Q1. Write a Python program to create a string and print its first and last characters.
Q2. Write a Python program to slice and print the word "Python"
from the string "I love Python programming"
.
Q3. Write a Python program to use a loop to print each letter in the word "STRING"
.
Q4. Write a Python program to concatenate "Hello"
and "World"
with a space in between and print the result.
Q5. Write a Python program to replace "dog"
with "cat"
in the string "The dog is cute"
.
Q6. Write a Python program to split the sentence "Welcome to Python"
into a list of words.
Q7. Write a Python program to check if the word "code"
exists in the string "codepractice.in"
.
Q8. Write a Python program to convert the string "python programming"
to uppercase.
Q9. Write a Python program to print the length of the string "Technovlogs"
.
Q10. Write a Python program to use an escape character to print: She said "Hi"
.
Introduction to Python
Python Basics
Python Syntax
Python Comments
Python Variables
Python Data Types
Python Casting
Python I/O
Python Operators
Cotrol Structures
Data Structures
Python Strings
Python Lists
Python Tuples
Python Dictionaries
Python Sets
Python Arrays
Python Bytes and Bytearray
Date and Time
Functions and Module
File Handling
Python OOP
Advanced Concepts
Python Scope
Python Modules
Python JSON
Python RegEx
Python PIP
Python Try...Except
Python String Formatting
Python User Input
Python VirtualEnv
Python Math
Python DSA
Python DSA
Lists and Arrays
Python Stacks
Python Queues
Linked Lists
Python Hash Tables
Python Trees
Python Binary Trees
Binary Search Trees
Python AVL Trees
Python Graphs
Searching Algorithms
Sorting Algorithms