Menu
Incident Response Forensics
student_number = []
student_name ["mark","rob","Jessica"] Index is used to access elements in a list for example: student_name[0] == "Mark" student_name[1] == "rob" student_name[-1]="Jessica" Replacing an element in list Student_name[0] ="James" student_name ["James","rob","Jessica"] Add element to a list: student_name.append("mark") student_name ["James","rob","Jessica","mark"] Checking element in list: "mark" in student_name == True number = 5
if number == 5: print("Number is 5") else: print("Number is Not 5") Truthy and Falsy Value: Eg; Any number other than 0 has truthy value Eg: Empty string is falsy value python_book = True if not python_book: print("This will not execute") Multiple If Conditions: number = 3 python_book = True if number = =3 and python_book: print("This will work") if number == 17 or python_book: print("This will work too") Ternary if Statements a = 1 b =2 "bigger" if a > b else "smaller" Note: This can be super helpful in list comprehension. Numbers
Integer = Number Float = Decimal Number Code Example: Integer: answer = 42 Float: pi = 3.14159 Complex Number (Python 3): Easy TypeCast int(pi) == 3 float(answer) == 42.0 String: Python 2: ASCII Python 3: Unicode String Can be defined using: 'Jello World' = "Jello World" = """Jello World """ Example: "hello.capatalize() == "Hello" "hello".replace("e" , "a") == "Hallo" "hello".isalpha() == True "123".isdigit()== True #Useful when converting to Int Advanced "Some, csv, values".split(",") = ["some","csv","values"] String Format name = "PythonGo" Machine = 'BAL" "Great meeting you {0}. I am {1}".format(name,machine) Python 3.6 String Interpolation: f"Great meeting you {name}. I am {machine} Boolean and None: python_book = True java_book = False Used often with If Statement Note - Both Start with Capital Letter T and Capital F int(python_book) == 1 int(java_book)==0 ste(python_book) == "True" aliens_found= None |
Archives
April 2020
Categories |