Python Unit 3
Python Unit 3
Python Complex data types: Using string data type and string operations, Defining list
and list slicing, Use of Tuple data type. String, List and Dictionary, Manipulations Building
manipulation, Programming using string, list and dictionary in-built functions. Python
Definition:
A string is a sequence of characters enclosed within single (' '), double (" "), or triple (''' ''' or """ """) quotes
in Python.
String Operations:
Concatenation (+): Combines two strings.
str1 = "Hello"
str2 = "World"
result = str1 + " " + str2 # Concatenation
print(result) # Output: Hello World
29-10-2020 Side 2
• Repetition (*): Repeats a string a specified number of
times.python
• String Methods: Functions that perform various operations on strings (e.g., lower(),
upper(), replace()).
my_list = [1, 2, 3, 4, 5]
sublist = my_list[1:4] # List Slicing
print(sublist) # Output: [2, 3, 4]
3. Tuple Data Type:
Use: Suitable for representing fixed collections of values that should not be modified
during program execution.
my_tuple = (1, 2, 3)
4. String, List, and Dictionary Manipulations:
> Methods like split(), join(), strip(), etc., facilitate string manipulation.
• List Manipulation:
Methods like append(), remove(), extend(), etc., modify lists.
numbers = [1, 2, 3]
numbers.append(4) # List Method
print(numbers) # Output: [1, 2, 3, 4]
Dictionary Manipulation: