HLEI (OPC) PRIVATE LIMITED
PYTHON –
JOB READY
PRESENTED BY
CLASS-03 DEVENDER SINGH
HLEI (OPC) PRIVATE LIMITED
1. WEEK
1 Introduction 4 Operators
2 Data Type 5 Loops
3 String and String methods 6 Number Methods/math
module
Assessment- 1
Taking user input
This function first takes the input from the user and converts it
into a string.
A = Input(“Enter age ”)
HLEI (OPC) PRIVATE LIMITED
String
Anything that you enclosed between single and Double
quotation mark is considered as String
HLEI (OPC) PRIVATE LIMITED
Indexing in String
indexing refers to the process of accessing a specific element in
a sequence, such as a string or list, using its position or index
number.
HLEI (OPC) PRIVATE LIMITED
Slicing in String
You can return a range of characters by using the slice syntax
HLEI (OPC) PRIVATE LIMITED
Length of string
We can Find the length of a string using len() Function
HLEI (OPC) PRIVATE LIMITED
String Method
This provides a set of built-in Methods that can help us to modify
our String.
HLEI (OPC) PRIVATE LIMITED
1. upper()
This method is used to convert a String into Uppercase.
HLEI (OPC) PRIVATE LIMITED
Example of Uppercase
A = “Devender”
Print(A)
HLEI (OPC) PRIVATE LIMITED
2. lower()
This method is used to convert a String into Lowercase.
HLEI (OPC) PRIVATE LIMITED
Example of Lowercase
A = “DEVENDER”
Print(A)
HLEI (OPC) PRIVATE LIMITED
3. rstrip()
It can remove character.
A = “hello !!!!!”
print(a.rstrip(!))
Note: This Method only removes characters in the last position
HLEI (OPC) PRIVATE LIMITED
4. Replace
It is used to change or replace a string with another String and
also we can replace a single character.
A = “Hello”
Print(A.replace(“Hello”,”hi”))
Print(A.replace(“e”,”p”))
HLEI (OPC) PRIVATE LIMITED
5. Split
It splits the given string at the Specified instance and returns
the separated string as a list item.
A = “How are you”
print(a.split(“ ”))
HLEI (OPC) PRIVATE LIMITED
6. Capitalize
It converts the first character in uppercase and another
character in lowercase.
a = “devender”
Print(a.capitalize())
HLEI (OPC) PRIVATE LIMITED
7. Center
This method aligns the string in the center.
a = "How are you"
print(a.center(100))
HLEI (OPC) PRIVATE LIMITED
8. Count
This method returns the number of times the given Value
has occurred within the given string
X =“Devender”
Print(x.count(e))
HLEI (OPC) PRIVATE LIMITED
9. Endswith()
This method checks if the String ends with a given value. It
returns yes as true if no then it returns no as False
y = "welcome to my world."
x = y.endswith(".")
print(x)
HLEI (OPC) PRIVATE LIMITED
10. find()
This method checks the given String is present in our string
if yes then he can write the index no. of the string .
y = "welcome to my world."
x = y.find(“my")
print(x)
HLEI (OPC) PRIVATE LIMITED
11. isalnum()
It is used to check-in the string A-Z, a-z, or 1-9 present or not.
y = "welcome to my world."
x = y.isalnum()
print(x)
HLEI (OPC) PRIVATE LIMITED
12. isalpha()
It is Checked it is only the alphabets.
y = "welcome to my world."
x = y.isalnum()
print(x)
HLEI (OPC) PRIVATE LIMITED
12. islower()
It is Check the alphabets is lowercase.
y = "welcome to my world."
x = y.islower()
print(x)
The slice() function returns a slice object that is used to slice any sequence
HLEI (OPC) PRIVATE LIMITED
12. Slice()
The slice() function returns a slice object that is used to slice
any sequence
slice(start, stop, step)
HLEI (OPC) PRIVATE LIMITED
Slice Practice
A = “Python is easy”
sliceex= slice(3)
Print(A[sliceex])
Use also:
Sliceex = slice(1, 6, 2)
Sliceex= slice(-1, -4, -1)
Formatted string literals (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with f or F and writing expressions as {expression}
HLEI (OPC) PRIVATE LIMITED
f-string
Formatted string literals (also called f-strings for short) let you
include the value of Python expressions inside a string by
prefixing the string with f or F and writing expressions as
{expression}
ho = 12
print(f” hello everyone its {ho} hours”)
Formatted string literals (also called f-strings for short) let you include the value of Python expressions inside a string by prefixing the string with f or F and writing expressions as {expression}
HLEI (OPC) PRIVATE LIMITED
f-string print number
ho = 12
print(f” hello everyone its {ho} hours”)
If a decimal is present then:
N = n = 7.4567
Print(f” the value for this is approximate {n:.2f}”)
P = 5678.3
Print(f” the value for this is approximate {n:,}”)
Print(f” the value for this is approximate {n:,.2f}”)
HLEI (OPC) PRIVATE LIMITED
Practice Question
1.Wring a program in which you can create a strong password.
2.Write a program to generate a band name.
3.Write a program in which you get input from the user as a
number and Add them.
HLEI (OPC) PRIVATE LIMTED
Any Query