Tumgik
cloudpunjabi · 2 years
Link
The Python for loop is the counting loop that is used to iterate i.e., repeat itself over a range of values or a sequence like string, list, tuple, or dictionary.
The for loop is not similar to for keyword that is used in other programming languages. It works more like an iterator.
It is used to avoid the repetitiveness of the code.
1 note · View note
cloudpunjabi · 2 years
Link
Bubble Sort is a sorting algorithm used to sort list items in specific order either ascending or descending order by comparing two adjacent values and swapping them until the list items are not in the intended order.
The comparison and swapping are repeated through each iteration until the array is sorted in specified order called a pass. The number of passes is equal to the number of elements in the array minus one.
1 note · View note
cloudpunjabi · 2 years
Link
Insertion sort is a sorting algorithm that is used to build a sorted list by placing an unsorted element at its suitable place through each iteration.
For example, the sort of cards in the game is also insertion sort.
We assume the first card to sorted, then take an unsorted card and check whether it is greater or lesser than the first card place it to the right or left to the first card accordingly. Then we took the third card and put it in the correct place of the previously arranged car, then repeat the process for other cards.
2 notes · View notes
cloudpunjabi · 2 years
Photo
Tumblr media
Do you know how to create a leap year program in Python?  There can be different ways to write a program. But the best program is that program which is efficient for both user and computer system.
There is 4 best leap year program in python. Now, Let’s see the different leap year codes in python
1 note · View note
cloudpunjabi · 2 years
Link
Odd even number Program is one of the most basic programs in Python. It has very basic code but it is necessary to understand this program to have a better understanding of the other complicated program. This program is for building the foundation of Python Programming.
1 note · View note
cloudpunjabi · 2 years
Photo
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
Do you know how to reverse a string in python? If no, then no problem we have different ways to do so.
Reverse of a string is means simply writing the string from last to the first index in a reverse manner. Likewise, the reverse of “python” will be “nohtyp”.
There are 4 different methods to reverse a string
2 notes · View notes
cloudpunjabi · 2 years
Link
There can be several ways to write a python program to check prime numbers, but the best and most efficient methods are listed below:
Using for loop
Using while loop
Using math module
By defining a isprime() function
Using sympy library
Using primePy library
1 note · View note
cloudpunjabi · 2 years
Link
Bitwise operators in Python are used to perform binary calculations on the given integer. It compares the binary value of the given integer and performs specific operations bit by bit, hence the name suggests the bitwise operator.
There are six types of bitwise operators in Python that perform different types of operations on the given operands.
0 notes
cloudpunjabi · 2 years
Link
Comparison Operators in Python are the operators that compare the two operands and find the relation between the operands like greater or lesser than and then return either True or False.
As the comparison operators also check the relation of two variables, hence they are also called relational operators in Python.
There are six different types of comparison operators in Python
1 note · View note
cloudpunjabi · 2 years
Link
Identity operators in Python are used to compare two variables or objects in python. It checks whether both the operands or variables have the same memory location or not and then returns True or False accordingly.
It is not necessary that both the operands or variables are identical, they can be different but reference to same memory location.
There are two types of Identity Operators in Python, which are listed below:
is operator
is not operator
1 note · View note
cloudpunjabi · 2 years
Link
Logical operators are Python operator that works on some logic. They evaluate the operands on given logic and then either return True or False. Logical operators are also called Boolean Operators as Logical operators work on the boolean expression.
There are three logical operators in Python that work on different boolean logics. The three Python logical operators are listed below:
and operator
or operator
not operator
0 notes
cloudpunjabi · 2 years
Link
In simple words, a membership operator in Python is an operator that checks the membership of a value or variable. Membership operator is used to check whether a value, variable, or element exists in the given sequences like string, tuple, list, etc., or not.
Membership operators work only on the sequences data types like string, list, tuple, or dictionary.
1 note · View note
cloudpunjabi · 2 years
Link
Assignment Operators in Python are the operators that are used to assign the values of the expression to the variable on the left-hand side.
The assignment operators in Python use the ‘=’ symbol for assigning the value of the expression. In the assignment operator, the value of the right-hand side expression or operand is assigned to the left-hand operand.
1 note · View note
cloudpunjabi · 2 years
Link
Arithmetic operators in Python are the mathematical operators that are used to perform different mathematical operations like addition(+), subtraction(-), multiplication(*), and division(/), etc. on the operands.
Arithmetic operators can be both unary or binary operators i.e, they are used with one as well as more than one operand.
The Binary Arithmetic operators in Python are operators that are used on two operands. They generally perform mathematical calculations.
There are 7 binary Arithmetic operators in Python that perform different operations.
2 notes · View notes
cloudpunjabi · 2 years
Link
We can easily use this module by importing it using the code import math.
Math module contains different types of functions ranging from basic operations of mathematics such as addition(+), subtraction(-), multiplication(*), division(/) to advanced mathematical operations like trigonometric, logarithmic, exponential functions.
1 note · View note
cloudpunjabi · 2 years
Link
There are different ways to find the square root of a positive number in Python. The Python also has its own in-built function called the sqrt() function to find square root in Python. But there are also other methods that sqrt() function to find square root. The ways to create a Python program for finding the square root of a number:
The sqrt() function
The pow() function
The exponential operator
1 note · View note
cloudpunjabi · 2 years
Link
A dictionary is a mutable data type in python It is an ordered* collection of elements stored in form of a key: value pair. The colon separates the key from its corresponding value. Commas separate each key-value pair. The curly bracket encloses the elements of the dictionary.
For example, {1: “python”, 2: “java”, 3: “Html”} is a dictionary.
1 note · View note