In this tutorial, we will learn about variables in Python. We will cover the basics of declaring and using variables, including naming conventions.
Variables in Python are used to store data values that can be manipulated during program execution. Python is a dynamically typed language, meaning the data type of a variable can change at runtime.
When naming variables in Python, follow these conventions:
The syntax to declare variables in Python is simply assigning a value to a variable name:
variable_name = value
num
.# Declare and initialize an integer variable
num = 10
# Print the value of the variable
print(f'The value of num is: {num}')
The value of num is: 10
name
.# Declare and initialize a string variable
name = 'John'
# Print the value of the variable
print(f'The value of name is: {name}')
The value of name is: John
is_true
.True
to the variable.# Declare and initialize a boolean variable
is_true = True
# Print the value of the variable
print(f'The value of is_true is: {is_true}')
The value of is_true is: True