How To Use Variables in Python 3

Published on Aug. 22, 2023, 12:16 p.m.

Here’s an example of how to use variables in Python 3:

# integer variable
my_int = 42
print(my_int)

# string variable
my_string = "Hello, World!"
print(my_string)

# floating-point variable
my_float = 3.14
print(my_float)

# boolean variable
my_bool = True
print(my_bool)

In this example, we declare and initialize four different variables with different data types: an integer, a string, a floating-point number, and a boolean. We then use the print() function to output the value of each variable to the console.

Note that in Python, you don’t need to explicitly declare variables with a particular data type - the interpreter infers the data type based on the value that you assign to the variable. In many cases, this can make programming in Python more convenient and flexible.

Tags:

related content