Variables And DataTypes - Python Tutorials For Beginners #3


Variables

1Variabl1e1 = 24565876575678
2x = input()
3print(x)
4print(Variabl1e1)

Here I created a variable called "Variable1". Variables are use for storing data. Variables are like containers, they contain values.** First of all, write the name of the variable, Use the = sign, and assign the value. This is the syntax to create variables in Python programming.

These are some example variables.

1a = 12345
2b = "abc123"
3c = 12.5
4d = """
5This is multiline 
6Statement!
7"""
1print(Variable1) # Method 1
2# Output : 2456555554646
1print( 2456555554646 ) # Method 2
2# Output : 2456555554646

Here, We got the same output with two different methods of line code. However, Using variables is the better decision for future time to change the value of variables.

We use variables many times instead of writing the value. Because, We easily change the value of a variable in the whole code. We will quickly change the value of a variable in the code if any issue is found.


Rules For creating Variables

(1) Use Pascal or camel cases to create the variable. Ex. the_ New _Variable, TheNewVariable.
(2) Don’t set the name of the variable on any keyword for a function in Python.
(3) The name only contains alphanumerics and underscores.
(4) Names cannot start with a number.


Datatype

 1a = -554 # This is 'int' data type. 
 2x = 3.0  # This is 'float' data type.
 3b = " Pyton " # This is 'string' data type.
 4c = None # This is 'NoneType' data type.
 5d = True # This is 'boolean' data type.
 6e = complex(687+2j) # This is 'complex' data type.
 7list1 = [1,4,5,6,7,8,9,0,'gitesh'] # This is a 'list' data type.
 8tuple = (("Mango,apple"),("Cherry,lichi")) # This is a 'tuple' data type.
 9i = dict1 = {"Name ":" Gitesh", "Age":"15"} # This is a 'dictionary' data  type.
10g = {1,2,3,4,5,6,7,8,9,0} # This is a 'set' data type. 

Data type is one of the most essential topic in Python. Every advance Python project contains the data type concepts. The datatype of Python means the variety of data which we can use in Python programming. There are many data types present in Python. But in 99% cases we use these variables during Python programming.

 1# Variables With Different Data Types.
 2a = -554 # This is 'int' data type. 
 3x = 3.0  # This is 'float' data type.
 4b = " Pyton " # This is 'string' data type.
 5c = None # This is 'NoneType' data type.
 6d = True # This is 'boolean' data type.
 7e = complex(687+2j) # This is 'complex' data type.
 8list1 = [1,4,5,6,7,8,9,0,'gitesh'] # This is a 'list' data type.
 9tuple = (("Mango,apple"),("Cherry,lichi")) # This is a 'tuple' data type.
10i = dict1 = {"Name ":" Gitesh", "Age":"15"} # This is a 'dictionary' data  type.
11g = {1,2,3,4,5,6,7,8,9,0} # This is a 'set' data type. 
12
13# This Code Dispaly The Data Type Of All Variables.
14print("Type of a is", type(a))
15print("Type of b is", type(b))
16print("Type of c is", type(c))
17print("Type of d is", type(d))
18print("Type of e is", type(e))
19print("Type of f is", type(f))
20print("Type of h is", type(h))
21print("Type of h is", type(i))
22print("Type of g is", type(g))

Run This code and see the type of variables in the code.


Watch The Video Tutorial On Youtube