Using variables in python

Author: Al-mamun Sarkar Date: 2020-03-24 19:05:19

Variable is used to store different types of data. Python is a dynamically typed programming language, so we don't need to define its type for creating a variable. 

 

Using variables in python.

x = 12
y = 23.34
name= "Jone Doe"
is_local = true

Here we create some variables in different types.  

 

Print Variable:

x = 12
name= "Jone Doe"

print(name)

 

Rules for Creating Variable:

  • Start with a letter or the underscore.
  • Can't start with a number.
  • Can contain only alpha-numeric characters (A-z, 0-9) and underscores ( _ )
  • Variables are case-sensitive (name, Name, and NAME are three different variables)

Some Variable:

varname = "John Doe"
var_name = "John Doe"
_var_name = "John Doe"
varName = "John Doe"
VARNAME = "John Doe"
varname2 = "John Doe"

 

Camel Case, Pascal Case, and Snake Case:

myVarName = "John Doe" #Camel Case
MyVarName = "John Doe" #Pascal Case
my_var_name = "John Done" #Snake Case

 

 

Assign Multiple Values:

Assign multiple values to multiple variables

x, y, z = 10, 20, 30

Same value to multiple variables:

x = y = z = 100