- Integer : Int, or integer, is a whole number, positive or negative, without decimals, of unlimited length.
- Float : Float, or "floating point number" is a number, positive or negative, containing one or more decimals.
- Complex : Complex numbers are written with a "j" as the imaginary part. Used for advanced math and engineering, similar to floats but with an imaginary component.
- Strings are sequences of characters used for representing text or data.
- Strings in python are surrounded by either single quotation marks (' '), or double quotation marks(" ").
When you compare two values, the expression is evaluated and Python returns the Boolean answer. You can evaluate any expression in Python, and get one of two answers, True or False.
- Lists are used to store multiple items in a single variable.
- Lists are created using square brackets []
- Lists can contain members of the same or different types
- List items are ordered, changeable, and allow duplicate values.
- List items are indexed, Index start from [0]
- append() : Adds an element at the end of the list.
- extend() : Add the elements of a list (or any iterable), to the end of the current list.
- insert() : Adds an element at the specified position.
- remove() : Removes the item with the specified value.
- pop() : Removes the element at the specified position. If you do not specify the index, the pop() method removes the last item.
- del () : The del keyword also removes the specified index.
- count() : Returns the number of elements with the specified value.
- index() : Returns the index of the first element with the specified value.
- sort() : Sorts the list ascending, by default. To sort descending, use the keyword argument reverse = True.
- reverse() : Reverses the order of the list
-
Tuples are used to store multiple items in a single variable.
-
Tuple items are ordered, unchangeable, and allow duplicate values.
-
Tuples are written with round brackets( ).
-
Tuple items are indexed, Index start from [0].
-
count() : Returns the number of times a specified value occurs in a tuple.
-
index() : Searches the tuple for a specified value and returns the position of where it was found
-
Sets are used to store multiple items in a single variable.
-
Set items are unordered, unchangeable, unindexed and do not allow duplicate values.
-
Set items are unchangeable, but can remove items and add new items.
-
Sets are written with curly brackets{ }.
-
add() : Adds an element to the set.
-
intersection() : Returns a set, that is the intersection of two other sets.
-
pop() : Removes an element from the set.
-
remove() : Removes the specified element.
-
union(): Return a set containing the union of sets.
- Dictionaries are used to store data values in key:value pairs.
- Dictionary items are ordered, changeable, and does not allow duplicates.
- Dictionary items are presented in key:value pairs, and can be referred to by using the key name.
- Dictionaries are written with curly brackets { }, and have keys and values.
len() : To determine how many items a set has, use the len() function.
Python has usual logic conditions from math :
- Equals: a == b
- Not Equals: a != b
- Less than: a < b
- Less than or equal to: a <= b
- Greater than: a > b
- Greater than or equal to: a >= b
An "if statement" is written by using the if keyword.
The elif keyword is Python's way of saying "if the previous conditions were not true, then try this condition".
The else keyword catches anything which isn't caught by the preceding conditions.
This is less like the for keyword in other programming languages, and works more like an iterator method as found in other object-orientated programming languages. With the for loop we can execute a set of statements, once for each item in a list, tuple, set etc.
The for loop does not require an indexing variable to set beforehand.
- ๐ซ How to reach me: www.linkedin.com/in/pritaayu10