Site icon TestingDocs.com

Python Assignment Statements

Overview

Let’s learn about Python assignment statements in this tutorial with the help of some examples. In Python language, variables are created by the assignment statements.

Assignment Statement

An assignment statement assigns a value to a variable by using an assignment operator (=). Assignment operators link a name on the left-hand side of the operator with a value on the right-hand side.

Examples

Let’s explore some assignment statement examples.

length = 18

In this example, the integer 18 is assigned to the variable length

breadth = 2.75

In this example, the floating-point number 2.75 is assigned to the variable breadth

str= “World Cup”

In this example, the string “World Cup” is assigned to the string variable str. The assignment operator (=) should not be confused with an equal sign used in Mathematics.

 

Let’s take an example of the following assignment statement:

x = 9   # x holds 9

x=x+5

The second assignment statement does the following things:

To verify this, let’s print the value of the x using the print statement.

x = 9

x = x + 5

print(x)

Python Tutorials

Python Tutorial on this website can be found at:

https://www.testingdocs.com/python-tutorials/

More information on Python is available at the official website:

https://www.python.org

Exit mobile version