Python Variables

Updated: May 18


Variables are used to store data and take memory space based on the type of value we assigning to them. We create variables in Python is simple, we write the variable name on the left side of = and the value on the right side. We do not have to openly mention the type of the variable, python gather the type based on the value we are assigning. There are some rules for creating variables in Python.


  • The name of the variable must always start with either a letter or an underscore (_).

  • The name of the variable cannot start with a number like 2num is not a valid variable name.

  • The name of the variable cannot have special characters such as %, $, # etc, they can only have alphanumeric characters and underscore (A to Z, a to z, 0-9 or _ ).

  • Variable name is case sensitive in Python which means num and NUM are two different variables in python.


Python Variable Example

num = 100

str = "Rajesh"

print (num)

print (str)


Output:

100

Rajesh



Recent Posts

See All

Python Modules

A module is a file containing Python definitions and statements. A module can characterize functions, classes and variables. A module can likewise incorporate runnable code. Gathering related code int

Command Line Arguments in Python

Command Line Arguments are the arguments that are specified after the name of the program in the command line shell of the operating system. Python gives different ways of dealing with these types of