In this tutorial, you will learn about Python Variables. Variables are a container to store or hold the various type of data. Variables are kept your code more organized and maintained. Every programming language has a variable type and most are common in term of definition, name, and property of variables.
A Syntax of Python since Python 3.5 and above, you declare a variable type like this:
Create a Simple Python Variables
Let’s do some code practice how to create variables in Python.
Text – Strings Variables
Give a name like “message” or any name, There some variable naming rule will learn later.
I will store a text in variable “message”.
message = "Hello, Buddy !"
Output: Hello, Buddy !
This how to create a String Variable.
- Don’t use the number before a variable name like
The string also has some inbuilt useful method, follow this link to know more in-depth: Python Strings Tutorial
phone_number = 1234567890
Python Variables Naming Rules
Python is case sensitive language, so it must define (naming) of the variable is proper. Here are some pythons variables rules :
- A variable name must start with a letter or the underscore character (like _var or mVar)
- It can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
- Variable names are case-sensitive (var, Var, and VAR are three different variables)
- Can’t start with a number
Do comment if you have any doubt and suggestions on this tutorial.
:This example (Project) is developed in PyCharm 2018.2 (Community Edition)
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
All Python variables examples are in Python 3 version, so it may change its different from python 2 or upgraded versions.