Python Tutorials · Python Variables
Python Variables
Learn all about Python Variables in this comprehensive tutorial.
5 min read beginner
- •Variables are containers for storing data values.
- •Python has no command for declaring a variable.
- •If you want to specify the data type of a variable, this can be done with casting.
- •You can get the data type of a variable with the type() function.
- •String variables can be declared either by using single or double quotes:
- •Variable names are case-sensitive.
Variables
Variables are containers for storing data values.
Creating Variables
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
python
Variables do not need to be declared with any particular type, and can even change type after they have been set.
python
Casting
If you want to specify the data type of a variable, this can be done with casting.
python
Get the Type
You can get the data type of a variable with the type() function.
python
Note: You will learn more about
data types and
casting later in this tutorial.
Single or Double Quotes?
String variables can be declared either by using single or double quotes:
python
Case-Sensitive
Variable names are case-sensitive.
python
Module quiz
2 questions1
Which of the following is true about Python Variables?
2
What is the most common pitfall when working with Python Variables?
Answer all questions to submit.