Login
Your Email
Pasword
Home
Write
Trending
History
Liked
Dashboard

What are the Datatypes & Variables used in Python?

Variables and Datatypes are important part of python programming like other programming languages.

Do you have similar website/ Product?
Show in this page just for only $2 (for a month)
Create an Ad
0/60
0/180
Variables in Python
Variables are used to store references to the object stored in memory and are named locations . The names choosed for variables and functions are  Identifiers. 
In python Identifiers should follow these rules:
1.All identifiers should start with letter or underscore any digit cannot be used. 
my_var is valid identifier But 1digit is not valid.
2.Identifiers can contain letters, digits and underscores .
3.Identifiers can be of any length. 
4.Identifier can not be a keyword .
Common Keywords in python 3 are.
False
class
finally
is         
elif
if
or
yield   
assert
break
except
in
pass
as
from
lambda
try
True
continue
for
None
return
raise
import
else
global
not
with
while
and
del
nonlocal 
def

 Data Types in Python
Python has 5  data types :
1. Numbers 
This data type supports only numerical values 
3 different numerical types are:
int  used for integer values like 5 . 
float used for floating point values like 1.5 . 
complex  used for complex numbers like 5+3j
2. String 
Strings are contiguous series of characters delimited by single or double quotes. 
Python don?t have any separate data type for characters so they are represented as a single character string.
E.g:
>>> name = "abcd" # a string
 >>> mychar = 'a' # a character
3. List 
List allows to add, delete or process elements in very simple ways. List is  similar to arrays.
Syntax for list is:
 >>> l = [1, 2, 3, 4]
4. Tuple 
Tuple is similar to list but once a tuple is created, nothing can be add, not delete, replace or can't reorder elements.
Syntax for tuple is:
>>> t1 = ()
5. Dictionary
Dictionary  is used to store key value pairs. It enables  quickly retrieve, add, remove, modify, values using key. Dictionary is  similar to what  associative array or hash on other languages.
Find = {
 'abc' : '111-222-333',
 'xyz' : '444-555-666'
 }
Find is a dictionary with two items.
CONTINUE READING
Datatypes
Variables
Python
Ayesha
Tech writer at newsandstory