Posts

Python Operators

  Operators are used to perform operations on variables and values. Python divides the operators in the following groups: Arithmetic operators Assignment operators Comparison operators Logical operators Identity operators Membership operators Bitwise operators Python Arithmetic Operators Arithmetic operators are used with numeric values to perform common mathematical operations: Operator Name Example Try it + Addition x + y Try it » - Subtraction x - y Try it » * Multiplication x * y Try it » / Division x / y Try it » % Modulus x % y Try it » ** Exponentiation x ** y Try it » // Floor division x // y Try it » Python Assignment Operators Assignment operators are used to assign values to variables: Operator Example Same As Try it = x = 5 x = 5 Try it » += x += 3 x = x + 3 Try it » -= x -= 3 x = x - 3 Try it » *= x *= 3 x = x * 3 Try it » /= x /= 3 x = x / 3 Try it » %= x %= 3 x = x % 3 Try it » //= x //= 3 x = x // 3 Try it » **= x **= 3 x = x ** 3 Try it » &= x &= 3 x = x &

set method in python

add() Adds an element to the set clear() Removes all the elements from the set copy() Returns a copy of the set difference() Returns a set containing the difference between two or more sets difference_update() Removes the items in this set that are also included in another, specified set discard() Remove the specified item intersection() Returns a set, that is the intersection of two other sets intersection_update() Removes the items in this set that are not present in other, specified set(s) isdisjoint() Returns whether two sets have a intersection or not issubset() Returns whether another set contains this set or not issuperset() Returns whether this set contains another set or not pop() Removes an element from the set remove() Removes the specified element symmetric_difference() Returns a set with the symmetric differences of two sets symmetric_difference_update() inserts the symmetric differences from this set and another union() Return a set containing the union of sets update() U

EX Dictionary | Python

# Create a dictionary and take input from the user and return the meaning of the # word from the dictionary Dict = {"ignore":"refuse to take notice of or acknowledge", "abandon":"cease to support or look after",         "exaggerate":"enlarged or altered beyond normal proportions", "prejudice":"preconceived opinion that is not based on reason or actual experience"} print("Enter the Word") Data1 = input() print(Data1, "means", Dict[Data1])

#10 Dictionary Method in Python

clear() Removes all the elements from the dictionary copy() Returns a copy of the dictionary fromkeys() Returns a dictionary with the specified keys and value get() Returns the value of the specified key items() Returns a list containing a tuple for each key value pair keys() Returns a list containing the dictionary's keys pop() Removes the element with the specified key popitem() Removes the last inserted key-value pair setdefault() Returns the value of the specified key. If the key does not exist: insert the key, with the specified value update() Updates the dictionary with the specified key-value pairs values() Returns a list of all the values in the dictionary

Python Lists And List Functions

Python has a set of built-in functions. Function Description abs() Returns the absolute value of a number all() Returns True if all items in an iterable object are true any() Returns True if any item in an iterable object is true ascii() Returns a readable version of an object. Replaces none-ascii characters with escape character bin() Returns the binary version of a number bool() Returns the boolean value of the specified object bytearray() Returns an array of bytes bytes() Returns a bytes object callable() Returns True if the specified object is callable, otherwise False chr() Returns a character from the specified Unicode code. classmethod() Converts a method into a class method compile() Returns the specified source as an object, ready to be executed complex() Returns a complex number delattr() Deletes the specified attribute (property or method) from the specified object dict() Returns a dictionary (Array) dir() Returns a list of the specified object's prop

String function in python

mystr = "Harry is a good boy" # print(len(mystr)) # print(mystr[::-2]) print(mystr.endswith("bdoy")) print(mystr.count("o")) print(mystr.capitalize()) print(mystr.replace("is", "are")) String function In Python Method Description capitalize() Converts the first character to upper case casefold() Converts string into lower case center() Returns a centered string count() Returns the number of times a specified value occurs in a string encode() Returns an encoded version of the string endswith() Returns true if the string ends with the specified value expandtabs() Sets the tab size of the string find() Searches the string for a specified value and returns the position of where it was found format() Formats specified values in a string format_map() Formats specified values in a string index() Searches the string for a specified value and returns the position of where it was found isalnum() Returns True if all char