Python_Advanced
Python_Advanced
3) Python Booleans
print("Integer:",bool(23))
Bitwise operators:
4) Python Strings
A string is essentially a sequence or array of textual
data.
Operations with Strings
• Length of a String: Length of a string using len() function.
• String as an Array: String is essentially a sequence of characters also
called an array.
• Loop through a String: Strings are arrays and arrays are iterable.
• String Methods: For Example str = ”jenkins”
• str.upper()
• str.lower()
• str.strip()
• str.replace(“Jen”,”Doc”)
• str.split(“k”)
• str.capitalize()
• str.find(”ins"))
List Indexes
Item/element in a list has its own unique index. List Comprehension
ToolsData = ["Maven", "Ansible", "Jenkins", "Sonar"] List comprehensions are used for
CloudData = [”AWS", ”AZURE", ”GCP"] creating new lists from other iterable’s like
Indexing : [0] [1] [2] [3]
lists, tuples, dictionaries, sets, and
even in arrays and strings.
ToolsData = ["Maven", "Ansible", "Jenkins", "Sonar"] names = [item for item in ToolsData if "o" in item]
EXAMPLE if "Maven" in ToolsData: print(names)
print("Maven is present.")
else:
print("Maven is absent.")
ToolsData.append("Fortify")
List Methods
• sort(): This method sorts the list in ascending order.
• reverse(): This method reverses the order of the list.
• index(): This method returns the index of the first occurrence of the list item.
• count(): Returns the count of the number of items with the given value.
• copy(): Returns copy of the list.
Conditional Statements
if Statement
if-else Statement
elif Statement
Python for Loop Nested Loops
EXAMPLE:
name("Sonar")
• Default Arguments CASE 2
def name(firsttool, secondtool, thirdtool):
print("Hello,", firsttool, secondtool, thirdtool)
• Keyword Arguments
name(thirdtool = "Ansible", firsttool = "Terraform",
secondtool = "Jmeter")
Python Modules
self method:
__Init__ method:
Init-> Self->
Class Object Binds the
Initialize attributes
Python Inheritance
ANY DIFFERENCE DID YOU FOUND?????
Converting JSON string to
python/Python to Json:
JSON stands for JavaScript Object Notation. It is a built-in
package provided in python that is used to store and
exchange data.
TRY CATCH
Python File Handling
file = open("someText.txt")
print(file.read())
3) Read a File:
file = open("Text.txt", "r")
print(file.read())
file.close