len(), this method will return the sum of the total items in an object. on a string, this function will return the number of characters.min()andmax(). this method are to find out what the minimum and maximum values are.count(), this method is to find out how many times an object appears in the list.sort(), this method sorts the list ascending by default and alse can be use dby specifying sorting criteria, such as key and reverse.- parameter
reverseis used to choose sorting type like descending or ascending. - parameter
keyis used to specify the sorting criteria.
- parameter
concatenation means joining strings together end-to-end to create a new string use the + operator.
replication is multiplication operator *. when used with one string and one integer, this operator * will reapating a single string however many times the given integer.
- one parameter
range(n), is used to create a series of numbers starting from 0 to n. - two parameter
range(n,p), is used to create a series of numbers starting from n until before p. - three parameter
range(n,p,q), is used to create a series of numbers starting from n, until before p, with each element having a difference of q.
operators in and not in, to find out a value or object is in a list. This function will retrun a boolean value true or false.
In assigning values to multiple variables, conventionally, we can mark the variables with the values you want, one at a time. But, Python has a more practical way, which is that we can assign values to multiple variables at once from a list or tuple element without needing to mark them one by one.
In an hewan2 list, there are 3 values in it. We want to define some different variable for each value in the list, so we can do this simultaneously by using a comma ,.
- Addition
+, math operation in which we add the numbers together to get their sum. - Subtraction
-, taking something away from a number. - Multiplication
*, to process of calculating the result when a number is taken times. - Division
/, to process of splitting a specific amount into equal parts. - Modulus
%, is the remainder after dividing one number by another. - Exponentiation
**, in math is defined as the operation used to represent repeated multiplication. - Floor Division
//, a normal division operation except that it returns the largest possible integer.
- Equal
==
- Not equal
!=
- Greater than
>
- Less than
<
- Greater than or equal to
>=
- Less than or equal to
<=
and, is used to combine conditional statemnets. Both conditions must be fullfilled.
or, is used to check that there is at least on true. If just one side i strue the entire expression is true. Just one condition must be fullfilled.
=equal.+=add and assign.-=subtract and./=divide and.*=multiply and.%=modulus and.**=exponent and.//=floor division.
x = 10
# add and assign
x += 2 # x = 12
# subtract and
x -= 2 # x = 8
# divide and
x /= 2 # x = 5.0
# multiply and
x *= 2 # x = 20
# exponent and
x **= 2 # x = 1000
# modulus and
x %= 2 # x = 1
# floor division
x //= 2 # x = 3python will always evaluate the arithmetic operators first
-
ifonly a statement is True will be executd, if it is false it will not. In python, the body of the if the indentation indicates statement, the body starts with an indentation and the first unindented line marks the end. The output is non-zero values as true, none and () are interpreted as false. -
elseThe if...else statement evaluates test expression and will execute the body of id only when the test condition is true. if it is false it will not. -
elifIf the condition for if is false, it checks the condition of the next elif block and so on. if it is false the body of else is executed. Only one block among the severalif...elif...elseblock is executed according to the condition. In other words, we can say that elif is python way of sating "if the previous conditions were not true, then try this condition".
- for Loops For loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string). 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.
- Nested Loops Nested loop is a loop inside a loop. The "inner loop" will be executed one time for each iteration of the "outer loop".
- While Loops The while statement creates a loop that executes a specified statement as long as the test condition evaluates to true. The condition is evaluated before executing the statement.
- Break, is used to terminate the loop.
- continue, is used when we want to skip a particular condition and continue the rest execution.
- pass, is used as a placeholder for future code. When it's executed, nothin happen, but you avoid getting an error.
list comprehension is a way to generate new lists based on pre-existing lists or iterables. To create list comprehension you can use this syntax.
underscore _ including valid variable naming. In general _ can be used as a throwaway variable (variable is not to imporntant).
- syntax error, occur when python can't understant what we mean.
- exceptions, ooccur while the process is in progress are called exceptions and can be fatal if not handled.
















