PYTHON PROGRAMMING
UNIT 3
Python Complex data types
By
Pragya Rajvanshi
LEC-1
Today’s target
String
some built in function of string
1
String
A String represents a sequence of characters.
It is an immutable data type(you have created
a string, you cannot change it.)
Python Programming does not have a
character data type, a single character is
simply a string with a length of 1.
2
Accessing characters in Python String String slicing
substring = s[start : end : step]
Retrieve All Characters
3
4
String built-in function
1. capitalize() method
It is used to change the first letter of a string to
uppercase and make all other letters lowercase.
5
2. isalnum() Method 3. isalpha() Method
This method checks whether all the characters It is used to check whether all characters in the
in a given string are either alphabet or numeric String are an alphabet.
(alphanumeric) characters
6
4. isdecimal() Method 5. isdigit() Method
This method checks whether all the It returns “True” if all characters in the string are digits,
characters in a given string is digit. Otherwise, It returns “False”
6. index() Method
The index() method in Python is used to find the position of
a specified substring within a given string.
7
Syntax of index() 7. islower() method
[Link](substring, start=0, end=len(s)) This method checks if all characters in the string are
1. substring: The substring to locate
within the string s. lowercase.
2. start (optional): The starting index
for the search. Defaults to 0 if not
provided.
3. end (optional): The ending index for 8. isnumeric() Method
the search. If not provided, it
defaults to the length of the string. It is used to determine whether the string consists of
numeric characters or not
8
9. isidentifier() Method
This method is used to check whether
a string is a valid identifier or not
Note:
A string is considered as a valid identifier
if:
It only consists of alphanumeric
characters and underscore (_)
Doesn’t start with a space or a
number
9
10. upper() Method 11. isupper() method
It creates a new string This method returns whether all characters in a string are uppercase or
with all lowercase letters not.
changed to uppercase.
This method does not
change the original string
instead it simply returns a
new one.
12. lower() Method
It converts all uppercase letters in a string to their lowercase.
10
11