Blog

python tutorials and learn python

Created with Sketch.

Python program that generates a random number between a given range

Python program that generates a random number between a given range The program imports the random module and then uses the randint() function to generate a random integer between 1 and 100 (inclusive) and print it. You can also generate a random number between a given range by using the random() function from the random…
Read more

Python program that swaps the values of two variables:

Here is a Python program that swaps the values of two variables: The program uses a temporary variable, “temp” to store the value of x, then assigns the value of y to x, and finally assigns the value of temp (original value of x) to y. Another way to swap two variables is by using…
Read more

Here is a Python program that solves a quadratic equation of the form ax^2 + bx + c = 0:

Here is a Python program that solves a quadratic equation of the form ax^2 + bx + c = 0: The program prompts the user to enter the coefficients of the quadratic equation using the input() function, and stores them in variables a, b, and c. It then calculates the discriminant (d) using the formula…
Read more

Here is a Python program that calculates the area of a triangle given the base and height:

Here is a Python program that calculates the area of a triangle given the base and height: The program uses the formula for the area of a triangle (base * height / 2) to calculate the area. It prompts the user to enter the base and height of the triangle using the input() function and…
Read more

Here is an example of a Python program that performs basic arithmetic operations:

Here is an example of a Python program that performs basic arithmetic operations: The program uses the basic mathematical operators for addition (+), subtraction (-), multiplication (*), division (/), floor division (//), modulus (%), and exponentiation (**) to perform the corresponding arithmetic operations. You can run this program by saving it in a file with…
Read more

Here is a simple Python program that prints “Hello Python”:

You can also use the print() function to print a string in python You can run this program by running the python file from command line. Like: It will print “Hello Python” on the console. You can also use an IDE (Integrated Development Environment) like Pycharm to run the code and see the output.

Python Logical Operators: and, or, not

Python Logical Operators: and, or, not We can apply for all types. For boolean Types Behaviour:and –> If both arguments are True then only result is Trueor –> If at least one arugemnt is True then result is Truenot –> ComplementTrue and False –> FalseTrue or False –> Truenot False –> True For non-boolean Types…
Read more

Python OPERATORS (PYTHON FUNDAMENTALS)

Python OPERATORS  The operator is a symbol that performs certain operations.  Python provides the following set of operators             1) Arithmetic Operators            2) Relational Operators OR Comparison Operators            3) Logical operators            4) Bitwise operators   …
Read more

Python Escape Characters (PYTHON FUNDAMENTALS)

Python Escape Characters In String literals, we can use escape characters to associate a special meaning. The following are various important escape characters in Python1) \n —> New Line2) \t —> Horizontal Tab3) \r —> Carriage Return4) \b —> BackSpace5) \f —> Form Feed6) \v —> Vertical Tab7) \’ —> Single Quote8) \” —> Double…
Read more

Python None Data Type (PYTHON FUNDAMENTALS)

None Data Type  None means nothing or No value associated. If the value is not available, then to handle such types of cases None is introduced. It is something like a null value in Java. Eg:def m1():a=10print(m1())None