Python abs() Function

Python abs() Function The Python abs() method returns the absolute value of a number. It accept one argument of type integer or a floating point number. If the input argument is a complex number, its returns the magnitude. Example 1. Below is the sample Python program to calculate the absolute value of a integer and floating point number. Write the below script in a python script:

Run the script and see the output: 10 3.638 Example 2. Here is another example of calculating absolute value of a complex number.…

Read More

Python – Strings

Python Strings A string is a sequence of characters and a character is can be a alphabet, digit or symbol. The Python treated any sequence of character’s enclosed in quotes as a string.

Python treated both single and double quted sequence as string. But in results of any string will be in a single quote only. like: ‘Welcome’ String Concatenation In Python strings have operation symbols too. Using a plus (+) symbol concatenate two strings. let’s type below example on Python shell.

The result will be same ‘Hello…

Read More

Docker Python Example

Run Python Application with Docker You can run a Python script using Docker containers. This tutorial will help you to run a Python script over command line within Docker isolated environment. Run Python Example within Docker Create Python Script – First, create a sample Python script to run on web server under the Docker container. Edit in your favorite text editor. nano Add the following content:

Create Dockerfile – Next create a file named Dockerfile under the same directory. Edit Dockerfile in a text editor: nano Dockerfile…

Read More

Python – Indentation

Python Indentation In Python, The indentation is the white space at the beginning of a line to define scope. Generally the other programming languages uses brackets to defined the scope of a function, loop etc. Python uses indentation instead of brackets for this purpose. Python Indentation Example Open a Python terminal and run below example: a = “Rahul” def myfun(): b = “TecAdmin” print(a) print(b) myfun() In above example, line number 3,4 and 5 have blank spaces before them. This is known as indentation. You can use any number of…

Read More

Python – Variables

Python Variables and Assignment A variable is a name, which represents a value. To understand it, open a Python terminal and run below command. id = 10 You will not see any result on screen. Then what happens here? This is an assignment statement, where id is a variable and 10 is the value assigned to the variable. A single equal (=) is an assignment operator. Where left side of the operator is the variable and right side operator is a value. Once a value is assigned to the variable,…

Read More

Python – Introduction

Python Introduction Python is a widely used general-purpose, high-level programming language. It was built by Guido van Rossum during 1985– 1990. Like Perl, Python source code is also available under the GNU General Public License. The Python programming language is being used in web development, machine learning applications, as well as all the state-of-the-art technology in the software industry. This code was designed with an emphasis on readability, and its syntax allows programmers to express their concepts in fewer lines of code. Python is a programming language that lets you…

Read More

Python – If…else

Python if else Statments If-else is the decision making statements in Python programming language similar to any other programming. Where execution of a block of statement is decided based on the result of if condition. If it evaluates a condition to true, then if block code is executed, on the false condition, the else block code is executed, which is optional. Basically, there are 4 types of if statements. if statement if-else statement else-if ladder statement nested if statement 1. Python – if Statement Example This is simple if condition,…

Read More