Python abs() Method 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:
# A sample python program to get absolute value of
# an integer or floating point number
num1 = -10
num2 = -3.638
Run the script and see the output: 10 3.638 Example 2. Here is another example of calculating absolute value of a complex number.…
Python Strings A string is a sequence of characters. The Python treated any sequence of character enclosed in quotes as string.
Use any of the above quotes, the result will remain in single quote in Python. ie. ‘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.
'Hello ' + 'World'
'Hello ' + "World"
The result will be same ‘Hello World’ Next, try with some digits enclosed with and without quotes.
Python checks for the types of values, based…
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 script.py in your favorite text editor. nano script.py Add the following content:
print("Welcome to Tecadmin.net");
print("This is Python running in Docker");
Create Dockerfile – Next create a file named Dockerfile under the same directory. Edit Dockerfile in a text editor: nano Dockerfile…
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…
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,…
Python Introduction Python is a general-purpose, interpreted and high-level programming languages. It is a powerful and easy to use language. It is one of the most used programming languages by the highly professional programmers. The Python was crated by Mr Guido van Rossum and released in 1991. Obtaining Python Python is a free language available for every one. You just need a computer to download and install it. Python works on almost all the operating systems. For Windows systems visit Python official site and download the latest version. For Linux,…
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,…